我搜索过像https://developer.chrome.com/apps/app_identity这样的教程,但我看不到如何检索在 chrome 中登录的用户的电子邮件地址。我只能获取 chrome.identity api https://developer.chrome.com/apps/identity 的 token
因此获取 token 的示例代码有效
chrome.identity.getAuthToken({'interactive': true}, function(token) {
console.log('user token: ' + token);
});
但是从这里我如何获取电子邮件。
注意:这是针对应用程序而不是扩展程序,因此 context_script 在我的身份验证示例 list 中不起作用。另外 chrome.identity.getProfileUserInfo 适用于 beta 版本 37,我也尝试过,但 enail 是空的。
我别无选择,但我知道有一种方法可以获取电子邮件。
最佳答案
哈哈,回答我自己的问题。
简短回答:您只需在 list 文件中添加电子邮件范围
长答案:我必须使用 google plus api。 Google 已弃用 OpenID 2.0,现在根据 https://developers.google.com/accounts/docs/OpenID2 使用 Google Plus 登录和 api 。 所以我上面提到,我没有使用 xhr method = "GET, url='h t tps://www.googleapis.com/plus/v1/people/me' 调用 Google Plus 时获取电子邮件地址。所以响应仅显示基本信息,例如姓名、性别、图像等,但没有电子邮件。为了获取电子邮件,您必须在 list 文件中添加电子邮件 token ,如示例所示
"permissions": ["identity",
...,
],
"oauth2": {
// client_id below is specifc to the application key. Follow the
// documentation to obtain one for your app.
"client_id": xyz,
"scopes": ["https://www.googleapis.com/auth/plus.login",
"https://www.googleapis.com/auth/userinfo.email"] **<-this one**
}
....
现在,在您的回复中,当 ypou 调用 xhr method = "GET, url='h t t ps://www.googleapis.com/plus/v1/people/me' 时,您将获得基本用户信息以及 电子邮件
关于javascript - Chrome应用程序,获取登录用户的电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25301018/