Mirror API and Node.JS

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

I can make calls using raw HTTP without any problems, so I know that I am white specified for the API, I authenticate and authorize correctly, and correct areas are corrected and that’s it. If I use the same access_token to insert into the timeline, I get an error in the callback. I also open the plus API, and calls using this API work fine.

code snippet for detecting an API that works without problems:

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

The code fragment to 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 recorded during the callback:

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

Any indication of what is required, how to provide it, or how to further debug such errors?

+4
source share
1 answer

UPDATE : the resource property is no longer required, so the source 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 ++' ); }); 
+5
source

Source: https://habr.com/ru/post/1479846/


All Articles