【发布时间】:2016-11-15 07:56:42
【问题描述】:
我已经搭建了一个 Web 应用程序,它能够使用 Passportjs 和 Google Oauth2 注册用户。在范围内注册用户时,我要求访问 Google Plus API 并检索要保留在 MongoDB 中的 accessToken 和 refreshToken。
稍后在应用程序中,我尝试调用 API 来检索 Google Plus 用户配置文件进行测试。我在代码中遵循以下步骤
var oAuth2 = googleCredentials.oauthClient(); // 设置一个新的 Oauth2 // 使用项目凭据的客户端
然后检索此特定用户的 access_token 和 refresh_token 并设置如下凭据
oAuth2.setCredentials({
access_tokens: user[0].access_token,
refresh_tokens: user[0].refresh_token
});
然后进行 API 调用
plus.people.get({
userId: 'me',
auth: oAuth2
}, function (err, response) {
console.log(err);
res.send(response);
});
但我的应用程序错误记录了以下错误
[错误:未设置访问或刷新令牌。]
任何帮助将不胜感激
【问题讨论】:
-
我什至通过访问 url googleapis.com/oauth2/v1/tokeninfo?access_token=[myaccess token] 检查了访问令牌的有效性并收到了肯定的响应,但真的无法理解为什么 API 调用总是报告错误 a上文提到的。非常感谢任何帮助