Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get email address from Google Plus API once i got the token

I have got accesstoken using oauth2.0. I am able to get the person name, gender, etc but I am not able to get the email address of the user.

Could any one please paste some sample code or any suggestions on how to get the email address from the google plus API?

like image 568
srp Avatar asked Jun 07 '12 16:06

srp


2 Answers

You can retrieve a user's email address if they specifically authorize your application to see their email address.

Set your scopes to:

https://www.googleapis.com/auth/plus.login
https://www.googleapis.com/auth/userinfo.email

The JavaScript calls look like this:

gapi.client.load('oauth2', 'v2', function() {
  gapi.client.oauth2.userinfo.get().execute(function(resp) {
    // Shows user email
    console.log(resp.email);
  })
});

gapi.client.load('plus', 'v1', function() {
  gapi.client.plus.people.get( {'userId' : 'me'} ).execute(function(resp) {
    // Shows other profile information
    console.log(resp);
  })
});

More information https://developers.google.com/+.

Note that you do not need scopes for plus.me or userinfo.profile.

like image 196
Chris Cartland Avatar answered Oct 17 '22 03:10

Chris Cartland


Exposing E-mail addresses of people who have not set it to be visible to 'Public' would obviously be a privacy issue, so that's not possible.

Exposing E-mail addresses of people who have set their E-mail address visibility to 'Public' is possible, but not yet there. It is currently an open issue

Edit: The issue is resolved now, so you can follow the steps in the other answer to get it.

like image 27
Hari Menon Avatar answered Oct 17 '22 03:10

Hari Menon