Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Google sign in Android

I'm trying to get a user token ID using the new Google play services 8.3 and as documented I pass the server ID:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)     .requestIdToken(getString(R.string.server_client_id))     .requestEmail()     .build(); 

but I'm still getting un successful result as below:

{statusCode=unknown status code: 12501, resolution=null} 

and documented here GoogleSignInStatusCodes

The sign-in was cancelled by the user. i.e. the user cancelled some of the sign-in resolutions, e.g. account picking or OAuth consent.

Constant Value: 12501

That is not my case, as I already picked an account. Any idea what could be the reason?

like image 946
Metwalli Avatar asked Nov 07 '15 13:11

Metwalli


People also ask

How do I change the Google sign-in button text?

Or based on whether it is a sign-in or sign-up flow, you want to switch between “Sign in with Google” and “Sign up with Google” text. As you might already know, to set the text on an Android Button , you can use android:text="{string}" attribute in your layout XML.

What is GoogleSignInClient?

public class GoogleSignInClient extends GoogleApi<GoogleSignInOptions> A client for interacting with the Google Sign In API.

How do I sign into Android Studio?

If this is your first time using a Google services sample, check out the google-services repository. Open Android Studio. Select File > Open, browse to where you cloned the google-services repository, and open google-services/android/signin .


2 Answers

I had exactly the same problem and i have found the solution.

If you follow the documentation found here: https://developers.google.com/identity/sign-in/android/start-integrating

The first step tells you to create the configuration file (which creates an OAuth 2.0 client ID for you and inserts it into the google-services.json)

Then later, it says again about creating a OAuth 2.0 client ID, but this time it says that you have to do it for Web application

And this is the confusing part! (at least for me) because i was just taking the client id created for the android OAuth and not creating a new one for Web application (I thought the documentation was just redundant or something)

As it says, it is this one, and only this one the one you have to use as a parameter of the methods requestIdToken or requestServerAuthCode.

Forget about using the Android OAuth ID in this methods because then you will get all the time the ugly status code response 12501.

I think the main problem is that the documentation is a bit confusing about this. Or maybe because it is a bit strange the fact that you have to create two OAuth IDs.

So as a summary, you need TWO OAuth IDs, one for android and one for web application, and you have to set each one in the correct place.

like image 148
Kaizie Avatar answered Oct 01 '22 07:10

Kaizie


I was struggling with this and wasted almost a week in it.

This is how I got it worked.

  1. Import Project in AndroidStudio
  2. Create debug keystore for project.
  3. Create SHA1 signature for project using debug keystore.
  4. Using SHA1 signature, register your app for Google Signin on Google Developer Console.
  5. Generate a Google Configuration file there.(Put in Android Studio's app folder)
  6. Use Web Client ID from OAuth 2.0 credentials in your Android Project.
  7. Now, from Android Studio, generate debug build(APK) of your project.
  8. Mount the device in your system -> copy this signed debug version of APK and install it.

Last three steps 6, 7 and 8, are what you actually need to take care of. If you directly run the project then APK is not actually signed with the debug keystore and google does not recognise it at all.

like image 39
Master Avatar answered Oct 01 '22 08:10

Master