9

This is traditional way to obtain token from GoogleApiClient used in Google+ login:

String token = GoogleAuthUtil.getToken(apiClient.getContext(), getAccountNameFromGoogle(apiClient), SCOPE);

However, GetAccountNameFromGoogle method requires android.permission.GET_ACCOUNTS permission and in Android M Developer Preview 3, this permission is now marked as dangerous and grouped into contacts group. That means that if someone wants to login into my app he needs need to grant my app full contacts permissions which is a bit overkill.

Is there a way to achieve this without GET_ACCOUNTS permission?

One potential answer I found is obtaining account name from AccountPicker, but that forces user to pick his account it twice (once for Google Plus authentication and once for AccountPicker) which is also not very friendly solution.

2
  • I tried to use the G+ signin button here and successful signin without using android.permission.GET_ACCOUNTS permission. I found that it works on Lollipop and has a problem on M preview 3 when running to Plus.PeopleApi.getCurrentPerson(mGoogleApiClient).getDisplayName();, it will get null pointer. I have report the issue here.
    – bjiang
    Aug 27, 2015 at 23:22
  • Yes, I'm already using that sign in. However that only allows you to use APIs inside play services. If you want to forward token to the server or use on another APIs outside play services, you need to retrieve the token. Aug 28, 2015 at 6:41

1 Answer 1

0

So this is how I eventually solved it:

I ditched GoogleApiClient completely and switched to AccountPicker. It is not perfect, but I can still use all features of GoogleApiClient, albeit not that effortlessly.

Google's guide to this: https://developers.google.com/android/guides/http-auth

2
  • How did you get user information like name and other information from google plus without using googleApiClient? Jun 30, 2016 at 12:57
  • @VihaanVerma After I got token, I could use Google+ REST api with that token to retrieve all info. Jun 30, 2016 at 19:20

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.