Chrome应用,获取登录用户的电子邮件地址 [英] Chrome App, getting logged in user's email address

查看:211
本文介绍了Chrome应用,获取登录用户的电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了诸如 https://developer.chrome.com/apps/app_identity 的教程,但我看不到我如何检索用户的电子邮件地址登录铬。我只能获得chrome.identity api的令牌 https://developer.chrome.com/apps/identity



因此获得令牌的示例代码工作

  chrome.identity.getAuthToken({'interactive':true},function(token){
console.log('user token:'+ token);
});

但是从这里我怎么得到电子邮件。



注意:这是针对应用程序而不是扩展,因此context_script在auth示例的清单中不起作用。此外chrome.identity.getProfileUserInfo是为测试版本37,我也试过,但enail是空的。

我没有选择,但我知道有一种方法以获得电子邮件。

解决方案

哈哈回答我自己的问题。



<简短的回答:你必须在清单文件中添加电子邮件的范围



长答案:我必须使用google plus api。 Google已弃用OpenID 2.0,现在依照 https://developers.google使用Google Plus登录和API .COM /帐号/文档/的OpenID2
所以我上面提到,我没有通过使用xhr method =GET,url ='ht tps://www.googleapis.com/plus/v1/people/me '因此,回复只显示了姓名,性别,图片等基本信息,但没有发送电子邮件。为了获得电子邮件,您必须在清单文件中添加一个电子邮件令牌

 permissions:[identity,
...,
],
oauth2:{
// client_id以下是应用程序密钥的详细信息,请按照
//文档为您的应用程序获取一个
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 ='htt ps://www.googleapis.com/plus/v1/people/me',你将获得基本的用户信息以及电子邮件


I have searched tutorials like https://developer.chrome.com/apps/app_identity, but I cannot see how I can retrieve a user's email address logged in chrome. I can only get a token for the chrome.identity api https://developer.chrome.com/apps/identity

so the example code for getting the token works

chrome.identity.getAuthToken({'interactive': true}, function(token) {
    console.log('user token: ' + token);
});

but from here how do I get the email.

Note: this is for an app not an extension, thus context_script did not work in my manifest from auth example. Also chrome.identity.getProfileUserInfo is for the beta version 37, I tried it also but enail was empty.

I am out of options, but i know there is a way to get the email.

解决方案

Haha to answer my own question.

Short answer: you have to just add the scope of email in manifest file

Long answer: I had to use the google plus api. Google has deprecated OpenID 2.0 and now using Google Plus sign in and api according to https://developers.google.com/accounts/docs/OpenID2. So I mentioned above that I was not getting the email address on the call to Google Plus using xhr method = "GET, url='h t tps://www.googleapis.com/plus/v1/people/me'. So the response was only showing basic things like name, gender, image etc, but no email. In order to get the email, you must add an email token in the manifest file as in the example

  "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**
    }
    ....

Now in your response when ypou call xhr method = "GET, url='h t t ps://www.googleapis.com/plus/v1/people/me', you will get basic user info plus the email

这篇关于Chrome应用,获取登录用户的电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆