我正尝试在通过oAuth2认证后获得一个电子邮件地址。在我使用谷歌帐户验证获得code后,我将从google Plus获取用户,如下所示:
let oAuth2Client = new auth.OAuth2(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_CLIENT_CALLBACK);
const tokens = await getToken(oAuth2Client, code);
oAuth2Client.setCredentials(tokens);
plus('v1').people.get({ userId: 'me', auth: oAuth2Client }, function(err, response) {
.... This repsonse is the full user object from Google Plus
});如何获取电子邮件地址或电子邮件地址列表?我不想要所有其他的Google Plus信息。我已经将我的作用域设置为email,但我仍然获得了许多其他信息。我假设我需要向plus以外的其他内容发出请求,但是我在文档中找不到要做的事情。
发布于 2017-06-17 07:49:40
如果您设置了电子邮件作用域(https://www.googleapis.com/auth/userinfo.email),则可以使用oauth2("v2").userinfo.v2.me.get:
var google = require('googleapis');
....
google.oauth2("v2").userinfo.v2.me.get({
auth: oAuth2Client
}, function(e, profile) {
if ("email" in profile) {
console.log(profile.email);
} else {
console.log("scope email not set");
}
});https://stackoverflow.com/questions/44061876
复制相似问题