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

我在一个函数中创build一个oauth2client,并返回它。 我其实是通过身份证,秘密,redirecturl和凭证。 这些都是我所检查的正确。

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); 

然后,我在返回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; } }); 

然而,然后我得到一个错误消息说,authClient.request不是一个函数。

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

我不知道为什么我得到这个错误。 我也做了console.log(JSON.stringify(oauth_client))来检查请求函数,我没有看到任何。 有人提到,这不能显示完整的原型链,并且请求函数可能实际上在那里。

问题是“oauth_client”。我使用“google-auth-library”进行身份validation。

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

然后使用这个oauth2Client作为oauth_client。

不知道你是否解决了这个问题,但是试着检查你有权限的范围。

我得到这个错误,结果我的范围设置为“ https://www.googleapis.com/auth/youtube.readonly ”,然后当我将范围更改为“ https://www.googleapis.com/ auth / youtube.upload '&' https://www.googleapis.com/auth/youtube '我能够上传video,而不是得到错误authClient.request is not a function