Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome identity api to get profile info

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?

like image 474
Harshil Pansare Avatar asked Dec 06 '25 01:12

Harshil Pansare


1 Answers

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.com/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.com/auth/userinfo.email"
        ]   
    }  
like image 148
Sid Avatar answered Dec 08 '25 15:12

Sid