Hello i am getting google plus access token without using OAuth 2.0 client ID with scopes. But with this access token does not fetch email address. How to fetch user email address?
Is there any difference between accesstoken with and without OAuth 2.0 client ID?
I have used following code,
String accessToken="";
try {
accessToken = GoogleAuthUtil.getToken(
getApplicationContext(),
mPlusClient.getAccountName(), "oauth2:"
+ Scopes.PLUS_LOGIN + " "
+ Scopes.PLUS_PROFILE);
System.out.println("Access token==" + accessToken);
} catch (Exception e) {
e.printStackTrace();
}
There are 2 simple ways to get user Email from Google plus,
1.Through
Plus.AccountApi.getAccountName
like below,String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
2.Through
plus.profile.emails.read scope and REST end point
like below,Get the GooglePlus AccessToken
You need to pass
" https://www.googleapis.com/auth/plus.profile.emails.read"
this scope to get theAccessToken
from GooglePlus like below,Make a REST call to the endpoint and do simple JSON parsing
https://www.googleapis.com/plus/v1/people/me?access_token=XXXXXXXXXXXXX
You must declare the permission
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
in yourAndroidManifest.xml
to use these methods.Full Example from Google Developer site,
Do something like below to retrieve the authenticated user's Email from Google plus,
Fore more info read this
https://developers.google.com/+/mobile/android/people