我正在嘗試使用youtube analytics api設置nodejs。我目前正在使用刷新令牌來嘗試獲取訪問令牌。它在使用郵遞員時效果很好,但我似乎無法在nodejs中複製功能,並獲得400:invalid_request,但沒有提供額外的信息。通過nodejs庫獲取Youtube Analytics的invalid_request
這裏是我的代碼
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;
任何想法?如果這不起作用,我可以嘗試通過HTTP/REST構建查詢,但我更願意使用SDK。