nodejs googleapis,authClient.request不是一个函数

Eth*_*lis 11 google-api node.js google-api-client meteor google-api-nodejs-client

我正在一个函数中创建一个oauth2client,并返回它.我实际上传递了clien id,secret,redirect url和凭据.根据我的检查,这些都是正确的.

var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
...
credentials = {
      access_token: accessToken,
      refresh_token: refreshToken
};
oauth2Client.setCredentials(credentials);
Run Code Online (Sandbox Code Playgroud)

然后我在返回oauth2client对象的函数中执行此操作:

var plus = google.plus('v1');
console.log(JSON.stringify(oauth_client));
plus.people.get({ userId: 'me' , auth: oauth_client}, function(err, response) {
    if(err) {
        console.log(err);
    } else {
        console.log(JSON.stringify(response));
        return response;
    }
});
Run Code Online (Sandbox Code Playgroud)

但是,然后我收到一条错误消息,指出authClient.request不是函数.

TypeError:authClient.request不是createAPIRequest中的函数(/node_modules/googleapis/lib/apirequest.js:180:22)

我不确定为什么会出现这个错误.我也做了console.log(JSON.stringify(oauth_client))来检查请求函数,我没有看到任何.有人提到这不能显示完整的原型链,并且请求函数可能实际存在.

san*_*ari 3

问题出在“oauth_client”。我使用“google-auth-library”进行身份验证。

var googleAuth = require('google-auth-library');
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
oauth2Client.credentials = credentials;
Run Code Online (Sandbox Code Playgroud)

然后使用这个oauth2Client作为oauth_client。

  • const auth = new googleAuth(); 类型错误:googleAuth 不是构造函数 (11认同)