nodejs googleapis,authClient.request不是一个函数 [英] nodejs googleapis, authClient.request is not a function
问题描述
我在一个函数中创建了一个oauth2client,并返回它。实际上,我确实通过了客户ID,秘密,重定向网址和凭证。这些都是我检查过的正确。
var OAuth2 = google.auth.OAuth2;
var oauth2Client =新的OAuth2(CLIENT_ID,CLIENT_SECRET,REDIRECT_URL);
...
凭证= {
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进行身份验证。
var googleAuth = require('google-auth -图书馆');
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId,clientSecret,redirectUrl);
oauth2Client.credentials = credentials;
然后使用这个oauth2Client作为oauth_client。
I am creating an oauth2client in one function like so and returning it. I actually do pass in the clien id, secret, redirect url, and credentials. Those are all correct from what I have checked.
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);
I then do this in the function where the oauth2client object is returned:
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;
}
});
However I then get an error message saying that authClient.request is not a function.
TypeError: authClient.request is not a function at createAPIRequest (/node_modules/googleapis/lib/apirequest.js:180:22)
I'm not sure why I get this error. I also did console.log(JSON.stringify(oauth_client)) to check for a request function and I didn't see any. Someone mentioned that this can't display the full prototype chain and that the request function might actually be there.
The problem is with "oauth_client".I used "google-auth-library" to authenticate.
var googleAuth = require('google-auth-library');
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
oauth2Client.credentials = credentials;
and then use this oauth2Client as oauth_client.
这篇关于nodejs googleapis,authClient.request不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!