Retrieves email from a Google Plus account on an Android application
So, I let users sign in to their Google+ accounts on my app. Now I can get their profile URL and display name. What I want to do now is receive their emails. I’m not sure how to get this information. I’ve added scope https://www.googleapis.com/auth/plus.profile.emails.read
and it successfully requests my permission to access my email when I sign in. I’m just not sure how to retrieve user emails right now.
For usernames, I do this :
String currentPersonName = mPlusClient.getCurrentPerson().getDisplayName();
So basically what I want to do is this:
String currentPersonEmail = mPlusClient.getCurrentPerson().getEmail();
But apparently this is not the right approach. Does anyone know how to get emails? Thank you.
Solution
Get the user’s email address:
private GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
emailAddr = Plus.AccountApi.getAccountName(mGoogleApiClient);
Another way is to query the plus.profile.emails.read scope of Google+ (as you did), but instead of displayName, look for jsons of type “emails”, see code example here .