我试图使用Google API Node.js客户端,使用OAuth2 API检索登录用户的名称。如何从OAuth2 Google API获取电子邮件和个人资料信息?
按照使用示例,我设法做了登录,但我找不到获取配置文件信息的方法。
我没有使用People API和Plus API,因为据我所知,OAuth2包含https://www.googleapis.com/auth/userinfo.profile,这应该足够用于该任务。
我已经看到了一些类似的问题,并试图这样一个的解决方案,但它没有工作,也许是太旧(?)
With the npm package googleapis how do I get the user's email address after authenticating them?
看着其他的API像谷歌表,这是可能的调用其功能是这样的:
var google = require('googleapis');
var sheets = google.sheets('v4');
...
sheets.spreadsheets.values.get({
auth: auth,
spreadsheetId: file_id,
range: my_ranges,
}, function(err, response){
...
}
);
但似乎OAuth2用户不喜欢的工作......
我不确定这是我正在寻找的答案。正如我前面所说,我有https://www.googleapis.com/auth/userinfo的范围。配置文件和https://www.googleapis.com/auth/userinfo.email,所以即使我不打算检查邮件,我是否真的需要包含gmail范围? – amlibtest
查看gmail.users.getProfile响应,它具有电子邮件地址,id,总消息和总线程数,但没有关于用户配置文件信息。所以恐怕我不能接受这个作为正确的答案 – amlibtest
我很抱歉我的误解。我将我的答案更新为“已添加”。请检查一下。该示例使用''oauth2.userinfo.get''检索用户信息。 – Tanaike