Skip to content Skip to sidebar Skip to footer

Chrome App, Getting Logged In User's Email Address

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 f

Solution 1:

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

Solution 2:

As an update, here it is a simpler way to get the email:

  1. you have to add both "identity" and "identity.email" to the permissions section on the manifest file.

  2. with that, using getProfileUserInfo should do the trick:

    chrome.identity.getAuthToken({'interactive': true}, function(token) {
       chrome.identity.getProfileUserInfo(
           function(info){console.log(info.email)}
       );
    }
    

Post a Comment for "Chrome App, Getting Logged In User's Email Address"