我对 NodeJs googleapis 模块有疑问。
我的简单测试:
var google = require('googleapis');
var analytics = new google.analytics('v3');
var OAuth2 = google.auth.OAuth2;
var config = require('./config.js')
var oauth2Client = new OAuth2(config.clientId, config.clientSecret);
// Retrieve tokens via token exchange explained above or set them:
oauth2Client.setCredentials({
access_token: config.accessToken,
refresh_token: config.refreshToken
});
// get management list
analytics.management.accounts.list({ auth: oauth2Client }, function(err, response) {
console.log(err)
console.log(response)
});
我的结果:
Type Error: Cannot read property 'params' of undefined
at createAPIRequest (/Users/gkburdett/Documents/Applications/maestro-and-scout/node_modules/googleapis/lib/apirequest.js:76:39)
at Object.Analytics.management.accounts.list (/Users/gkburdett/Documents/Applications/maestro-and-scout/node_modules/googleapis/apis/analytics/v3.js:342:16)
at Object.<anonymous> (/Users/gkburdett/Documents/Applications/maestro-and-scout/server/google/test/simpleTest.js:13:31)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
parameters.context.google 是一个空白对象。
如果我将 apirequest.js 第 76 行更改为空白对象,它会起作用。我在 GitHub 上提交了一个问题,但如果这是库的问题,我很难相信我是唯一一个遇到这个问题的人。