最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome identity api to get profile info - Stack Overflow

programmeradmin8浏览0评论

I want general profile information of user like birthdate, gender, username,etc. I am able to get email and unique profile id of user by using getProfileUserInfo method of identity api. It returns only email and id like this:

userinfo Object {email: "[email protected]", id: "1xxxxxxxxxxx49189xx"}

How do I get additional information?

I want general profile information of user like birthdate, gender, username,etc. I am able to get email and unique profile id of user by using getProfileUserInfo method of identity api. It returns only email and id like this:

userinfo Object {email: "[email protected]", id: "1xxxxxxxxxxx49189xx"}

How do I get additional information?

Share Improve this question asked Oct 16, 2015 at 5:50 Harshil PansareHarshil Pansare 1,1472 gold badges13 silver badges38 bronze badges 2
  • chrome.identity seems to be used for authentication purposes, not for whatever it is you want to do with personal info – Jaromanda X Commented Oct 16, 2015 at 6:00
  • So how do I get users other information? So far, I have authToken and unique userID. – Harshil Pansare Commented Oct 16, 2015 at 6:04
Add a ment  | 

1 Answer 1

Reset to default 9

Although I am not sure about birthday, but you can get user's information like id, name, given_name, family_name, link, picture, gender , locale.

Code:

chrome.identity.getAuthToken({
    interactive: true
}, function(token) {
    if (chrome.runtime.lastError) {
        alert(chrome.runtime.lastError.message);
        return;
    }
    var x = new XMLHttpRequest();
    x.open('GET', 'https://www.googleapis./oauth2/v1/userinfo?alt=json&access_token=' + token);
    x.onload = function() {
        alert(x.response);
    };
    x.send();
});

Just make sure you add the url under scopes in manifest.json:

"oauth2": {
        "client_id": "XXXXX",
        "scopes": [
            "https://www.googleapis./auth/userinfo.email"
        ]   
    }  
发布评论

评论列表(0)

  1. 暂无评论