我有一个包含以下详细信息的 JSON 对象:
{ access_token: 'access_token',
token_type: 'Bearer',
expires_in: 3599,
id_token: 'longstring'
}
使用 NodeJs 库“googleapis”如何获取上述回复的电子邮件地址。我不想使用 URL:https://www.googleapis.com/oauth2/v1/userinfo?access_token=your_access_token
最佳答案
获取像 introduction 中那样的 auth-object ,然后您可以使用getProfile方法:
function getEmailAddress(auth, callback) {
gmail.users.getProfile({
auth: auth,
userId: 'me'
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
callback(err, null);
} else {
callback(null, response.emailAddress)
}
});
}
关于node.js - 从 id_token Gmail OAuth 获取电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38583319/