In my android application I request google plus token which I send to server. I want to be able to get user information including his email address in server.
Here's a call that works but doesn't give me email:
GoogleAuthUtil.getToken(activity, Plus.AccountApi.getAccountName(googleApiClient), "oauth2:" + Scopes.PLUS_ME + " " + Scopes.PLUS_LOGIN + " " + Scopes.PROFILE);
With it I only get this information:
{
"id": "11213535252359196332836",
"name": "Name Surname",
"given_name": "Name",
"family_name": "Surname",
"link": "https://plus.google.com/+laskdjfksdjf",
"picture": "https://asdfsdafasdfasdfasdfasdfasdfsdaf7c/photo.jpg",
"gender": "male",
"locale": "en"
}
I found that I need to ask for userinfo.email permission, so I modified my call:
GoogleAuthUtil.getToken(activity, Plus.AccountApi.getAccountName(googleApiClient), "oauth2:" + Scopes.PLUS_ME + " " + Scopes.PLUS_LOGIN + " " + Scopes.PROFILE + " https://www.googleapis.com/auth/userinfo.email");
The problem is, that now getToken() call returns me this error:
09-16 18:53:57.311: W/System.err(26467): com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
09-16 18:53:57.316: W/System.err(26467): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
09-16 18:53:57.316: W/System.err(26467): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
09-16 18:53:57.316: W/System.err(26467): at lt.sm.discountcity.GPlus.getServerOnlineToken(GPlus.java:237)
09-16 18:53:57.316: W/System.err(26467): at lt.sm.discountcity.fragments.LoginFragment$5$1.runOnSeparateThread(LoginFragment.java:173)
09-16 18:53:57.316: W/System.err(26467): at lt.smtools.tasks.TaskManager$2.run(TaskManager.java:139)
09-16 18:53:57.316: W/System.err(26467): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-16 18:53:57.316: W/System.err(26467): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-16 18:53:57.316: W/System.err(26467): at java.lang.Thread.run(Thread.java:841)
Any ideas what am I doing wrong and how to solve this?