Question

I have a node.js program that I am trying to work with the googleapis module (https://github.com/google/google-api-nodejs-client) version 0.2.5-alpha.

I can make calls using the raw HTTP without problems, so I know I am white listed for the API, I am authenticating and authorizing correctly, and the correct scopes and everything are being requested. If I use the same access_token to do an insert into the timeline, I am getting an error in the callback. I am also discovering the plus API, and calls using this API are working fine.

Code fragment to discover the API, which appears to work without problems:

var client;
googleapis
  .discover( 'plus', 'v1' )
  .discover( 'mirror', 'v1' )
  .execute( function(err,data){
    console.log( err );
    client = data;
  });

Code fragment to do the call:

  client.mirror.timeline.insert({
    text: "test 1 "
  } ).withAuthClient(user.auth).execute(function(err,result,res){
      console.log( '++ start ++' );
      console.log( '+err   ', err );
      console.log( '+result', result );
      //console.log( '+res   ', res );
      console.log( '++ end   ++' );
  });

What is logged during the callback:

++ start ++
+err    { code: 400,
  message: 'Required',
  data: [ { domain: 'global', reason: 'required', message: 'Required' } ] }
+result undefined
++ end   ++

Any indication what is "Required", how to provide it, or how to further debug errors such as this?

Was it helpful?

Solution

UPDATE: the resource property is no longer required so the original code should just work instead of the proposed solution.

Since the node.js client library is based on the JavaScript client library, you need to set the request body in the "resource" property:

client.mirror.timeline.insert({resource: {
    text: "test 1 "
  }}).withAuthClient(user.auth).execute(function(err,result,res){
      console.log( '++ start ++' );
      console.log( '+err   ', err );
      console.log( '+result', result );
      //console.log( '+res   ', res );
      console.log( '++ end   ++' );
  });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top