node.js - Getting invalid_request for Youtube Analytics with nodejs library -


i trying setup nodejs youtube analytics api. using refresh token try , access tokens. works great when using postman can't seem replicate functionality in nodejs , 400: invalid_request no additional information provided.

here code

var google = require('googleapis'); var oauth2 = google.auth.oauth2; var oauthclient = new oauth2();  // retrieve tokens via token exchange explained above or set them: oauthclient.setcredentials({    access_token: "",    refresh_token: process.env["youtube_analytics_refreshtoken"] });  var youtubeanalytics = google.youtubeanalytics({    version: 'v1', auth: oauthclient });   var moduleexports = {     retrievedailybreakdownviews : function(){           var query = {           ids: 'channel==' + {channelid here},           'start-date': '2017-05-01',           'end-date': '2017-05-02',            metrics: 'views,estimatedminuteswatched',            dimensions: 'insightplaybacklocationtype',            sort: 'views'        }   youtubeanalytics.reports.query(query, (error, response) => {     console.log(error);     console.log(response);   }); } }  module.exports = moduleexports; 

any ideas? if doesn't work can try , build query through http/rest i'd prefer use sdk.

in order able refresh access token, need client_id , client_secret. what's happening under hood following request refresh token (referenced here):

post https://accounts.google.com/o/oauth2/token {     refresh_token: refresh_token,     client_id: this._clientid,     client_secret: this._clientsecret,     grant_type: 'refresh_token' } 

you'll need initialize oauth2 client :

var oauthclient = new oauth2(   your_client_id,   your_client_secret,   your_redirect_url ); 

you'll need provide refresh token generated using same client_id / client_secret if hardcode refresh token value


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -