New Google Sign in Android

I am trying to get the user token id using the new Google play 8.3 services 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 still get an unsuccessful result as shown below:

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

and documented here by GoogleSignInStatusCodes

Login has been canceled by user. that is, the user has revoked some of the login permissions, for example. account collection or OAuth consent.

Constant Value: 12501

This is not my business, as I have already selected an account. Any idea what could be the reason?

+76
android google-play-services google-identity
Nov 07 '15 at 13:34 on
source share
32 answers
  • one
  • 2

I had exactly the same problem and found a solution.

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

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

Then later he talks again about creating an OAuth 2.0 client ID, but this time he says you need to do this for a web application

And this is the confusing part! (at least for me), because I just took the client ID created for the OAuth android, and did not create a new one for the web application (I thought the documentation was just redundant or something else)

As the saying goes, it is this one, and only the one that you should use as the parameter of the requestIdToken or requestServerAuthCode methods.

Forget about using the Android OAuth identifier in these methods, because then you get a 12501 ugly status code response all the time.

I think the main problem is that the documentation is a bit confusing. Or maybe because it's a little strange that you need to create two OAuth identifiers.

So, as a summary, you need two OAuth identifiers, one for android and one for a web application, and you need to install them in the right place.

+102
Nov 13 '15 at 9:08
source share

I struggled with this and wasted almost a week.

This is how I worked.

  • Import a project into AndroidStudio
  • Create a debug repository for the project.
  • Create the SHA1 signature for the project using the debug repository.
  • Using your SHA1 signature, register your Google login application on the Google Developer Console.
  • Create a Google configuration file there. (Paste into the Android Studio application folder)
  • Use the web client ID from the OAuth 2.0 credentials in your Android project.
  • Now from Android Studio, create the debug assembly (APK) of your project.
  • Connect the device to your system -> copy this signed debug version of the APK and install it.

The last three steps 6, 7 and 8 are what you really need to take care of. If you run the project directly, the APK does not actually sign up with the debug repository, and Google does not recognize it at all.

+20
Jun 06 '16 at 12:49 on
source share

I had the same problem, after solving the research, he resumed that server_client_id contains an invalid value, or your google_services.json did not enable oauth_client with the client_id registered in your keystore.

 requestIdToken(getString(R.string.server_client_id)) 

R.string.server_client_id use the OAuth 2.0 client identifier for the web application . And the OAuth client ID for Android is used in google_services.json

Usually we use 2 keystore, 1 using the debug store and 1 using the signed keystore for publishing. Therefore, if we want in debugging and publishing mode, double-register your OAuth client ID for Android, 1 using SHA1 from the debug store and 1 from the signed key store for publishing.

small example in my google_services.json

  "oauth_client": [ { "client_id": "xxx-client-id.com", "client_type": 1, "android_info": { "package_name": "com.app.android", "certificate_hash": "xxxhash" } }, { "client_id": "yyy.client-id.com", "client_type": 1, "android_info": { "package_name": "com.app.android", "certificate_hash": "yyyhash" } } ], 
+16
Nov 15 '15 at 17:23
source share

I was getting the same problem because I created a client id like Android application

Instead, I deleted it and created a client identifier such as a web application, and I got rid of this problem.

+14
Nov 13 '15 at 12:06
source share

Just figure out how to solve it ... I got this error when trying to run the debug version of my application ... To fix this, add the credentials for your debug application on the developer console as well as on Google-services.json.

it fixed it for me!

+8
Nov 12 '15 at 20:49
source share

I had the same problem and solved with the following solution:

  • Create a configuration file (google-services.json) as described here and put it in the directory of your project / application
  • (As mentioned in other answers) Using the web application client ID for the requestIdToken method.
  • [My main problem] Sign your application if you are running in debug mode, as shown below:
  signingConfigs { release { storeFile file("myreleasekey.keystore") storePassword "password" keyAlias "MyReleaseKey" keyPassword "password" } } buildTypes { release { ... } debug { ... signingConfig signingConfigs.release } } 
+7
May 10 '16 at 9:33
source share

In my case, I also had to verify that the debug SHA-1 was added as a valid Android OAuth client.

+3
Dec 04 '15 at 23:15
source share

Now I understand.

So, first you should follow the top answers saying: 1. create an OAuth client identifier for web applications in the Google Developers Console and use it in requestIdToken() (get rid of status code 12501) 2. if you created an Android OAuth client identifier for your production hash key, create a new Android OAuth client ID for your debug hash key and integrate it into your google-services.json. (get rid of status code 12500)

And here is the last part: 3. You cannot immediately call requestIdToken() and requestEmail() . At least in my case, I got rid of Result: Status{statusCode=INTERNAL_ERROR, resolution=null} by deleting requestEmail() .

So good luck ...

+3
Jan 22 '16 at 23:42 on
source share

Use web app as server_client_id, not Android app

+3
Apr 13 '16 at 20:06
source share

I had the same problem and I noticed that the code 12501 was returned when the wrong value was contained in my server_client_id .

Since there is no detailed message, and the documentation for this error code is pretty bad, I don’t know if your problem has the same reason as mine.




My application is based on Android code from in this example (IdTokenActivity class). For it to work, I also needed to integrate the Google login into my application:

  • generated json configuration file with google input enabled
  • added google plugin and dependency on my gradle file
  • created the OAuth client ID for this application and saved it in my project as server_client_id
+2
Nov 09 '15 at 2:37
source share

Is your apk in debug mode? I think it only works with signed apk.

+2
Nov 09 '15 at 22:48
source share
  • Follow the ambiguous google doc.
  • Put google-services.json in the project directory
  • Install gradle as https://stackoverflow.com/a/330969/

  • Set server_client_id in string.xml. Your web client id does not support android client

+2
Feb 05 '16 at 5:14
source share

The problem I had was that SHA-1 I generated as with the wrong alias. The alias MUST be androiddebugkey . So I put the Android OAuth identifier in my google-service.json file. I put the web client id in requestIdToken (). And in my specific case, I generated SHA-1 with the androiddebugkey alias.

Google-services.json :

 "oauth_client": [ { "client_id": "ANDROID OAUTH ID-.....apps.googleusercontent.com", "client_type": 1, "android_info": { "package_name": "br.com.packagename", "certificate_hash": "SHA-1 HASH" } },{ "client_id": "WEB CLIEND ID......apps.googleusercontent.com", "client_type": 3 } ] 

Signature:

 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken("WEB CLIEND ID......apps.googleusercontent.com") .requestEmail() .build(); 
+2
Nov 09 '16 at 22:29
source share

Instead of R.string.server_client_id just use R.string.default_web_client_id .

When you copy the google-services.json file to the application, it automatically creates this string value. You do not need to copy the key from google-services.json to string.xml This worked for me.

+2
Dec 02 '16 at 7:32
source share

I solved this problem by clicking on Firebase support in Android Studio, which may not be relevant for users who are not Firebase users.

  • Go to Tools-> Firebase
  • Click "Connect your application to Firebase", it will appear as "Connected" in green after a successful connection.
  • Click "Add Firebase Authentication" to the application button, it will also turn green.

NOTE. Having a huge list of answers in this definitely confirms one thing. Google needs to update and confirm the documentation.

+2
Feb 01 '17 at 12:00
source share

If none of the above options work, check if the applicationId application in the build.gradle application is the same as your package name.

+1
Nov 19 '15 at 14:18
source share

I don’t know why, but SHA1 in android studio automatically changes, and therefore I get this error. To solve this problem, I updated the SHA1 of my firebase project settings with the new SHA1 of my Android studio and started working again.

+1
Sep 15 '16 at 19:00
source share

In my case, my credentials for Client ID for Android on the Google APIs Console contained only SHA-1 for my release, signed by the APK. Android Studio used the default debug storage to sign my debug collections, in which case the SHA-1 debug storage did not match the Android SHA-1 client online. My solution was to simply sign debug builds with the release key store.

In Android Studio, Build/Edit Build Types... , then select the debug build type and make sure Signature is set to your release certificate.

Set up a subscription to release

+1
Nov 15 '16 at 16:46
source share

I had the same problem and error 12501 , and was not higher for me.

My problem was that I used google Default web api created for me. after creating my own api error api disappeared and worked fine!

these are the following steps:

  • First, I created the SHA1 debug key and added it to the Firebase console. creating SHA1 from here .
  • create client id web api and android OAuth 2.0 from here
  • create google-service.json from the Firebase console and paste it into the application folder.
  • put this code for GoogleSignnOption

like this:

 gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken ("put the web app client Id that get from the link in developer console ") .requestEmail().build(); 

hint 1: I will find out that you need to create an Android client identifier and a web application.

tip 2: if you are from Iran, like me, you can get the user from Google, but you cannot AuthWithGoogle , and the result will fail in auth.signInWithCredential(credential) , and you had to use some proxy to return true.

this is the working full source of FireBaseAuthDemo on github:

enter image description here

hope full help

+1
Jan 01 '16 at 6:13
source share

If you use debug storage to create a project, you need to add the SHA-1 debug.keystore fingerprint to Firebase Console strong>.

  • Open a project on Firebase Console
  • Go to options. General tab
  • At the end of this page there is a field for adding SHA-1 Fingerprint
  • Insert SHA-1 in the console box.

To get SHA-1 for debug.keystore:

Mac / Linux:

 keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore 

Windows:

  keytool -exportcert -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore 

https://developers.google.com/android/guides/client-auth

It's all!

+1
May 05 '17 at 2:15 pm
source share

I also had this problem by following Google's instructions for Automatically sign my application . If you use this method to sign your applications, you will need to include the generated keystore fingerprint in your API credentials.

In the project browser, right-click on your application and select "Open Module" Settings.

Open Module Settings Screenshot | app | signed | config

It seemed to me that it was less confusing to put the .jks file in my project /app . In any case, run this line.

 keytool -list -v -keystore /home/user/keystores/android.jks 

You will be prompted for a password. Not sure if it is Key Password or Store Password , because mine are the same .: |

The console will spit out a bunch of fingerprints of the certificate. Take SHA1 and transfer it to your API credentials in the Google API Developer Console . You will need to enter it for the OAuth 2.0 client IDs Android OAuth 2.0 client IDs , even if you are not actually using this client_id in your application. If you use other android APIs, put the same SHA1 in the corresponding key credentials in the API keys too.

0
Mar 12 '16 at 5:29
source share

Obviously, first check that your sha1 key is correct for release. But if it still does not work, and you use google play 8.4.0 services (iecompile 'com.google.android.gms: play-services: 8.4.0'), the problem can be solved by modifying the GoogleSignInOption object. Instead:

 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestIdToken("YOUR_WEB_API_ID.apps.googleusercontent.com") .build(); 

You should use:

 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PLUS_LOGIN)) .requestScopes(new Scope(Scopes.PLUS_ME)) .requestEmail() .build(); 

This solves the error returning statusCode = INTERNAL_ERROR OR statusCode = Error 12501 OR statusCode = Error 12500. Then this gso object can be used to create GoogleApiClient, as shown below:

  mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addApi(Auth.GOOGLE_SIGN_IN_API,gso) // .addApi(Plus.API, null) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) // .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); 
0
Apr 12 '16 at 14:17
source share

Here is a new one. I tried 6 hours to enter the emulator with an identifier from my corporate Google Apps domain, to no avail, getting 12501 errors. On suspicion, I tried my personal gmail id and it worked. The same thing if I tried my corporate identifier on my phone. It turns out that the emulator did not have the correct settings for managing the mobile device so that my corporate identifier could log into the system.

So, if I want to test the emulator with this corporate identifier, I need to install the Google Play Store, then the MDM software and configure it.

0
Oct 30 '16 at 11:30
source share

From my strange experience with this error, I can say that you also need to try to restart the phone to get rid of this error :) I was implemented by Google Sign In using the G Suite accounts that are assigned using Google Admin. Thus, the first sign required the installation of Device Policy. After all the following steps were completed, he simply threw an error 12501. At the same time, the same application worked fine on other phones. So only reboot helped. But helped

0
Dec 07 '16 at 5:35
source share

Although there are already many validated answers to this question, I struggled to understand the logic. So, I come up with my research.

To get SHA-1, run it in the terminal:

 keytool -exportcert -keystore path-to-debug-or-production-keystore -list -v 

About OAuth 2.0 client IDs

  • OAuth for the Internet (in the application it is used as server_client_id )
  • OAuth for android (this must be created using the correct package name and fingerprint of the SHA-1 signature).

If you use another keystore for debugging and release, you need to create separate OAuth 2.0 client IDs using the appropriate package name and SHA-1.

You can create or edit OAuth 2.0 client IDs here https://console.developers.google.com/apis/credentials?project=

  • Transition to your application.
  • If you already have OAuth for Android, click its name and check the package name and SHA-1.

We can use the same keystore for debugging and release, storing the keystore data in the global (local, and not inside the project) gradle.properties and getting it in build.gradle , as shown below.

 def key_alias = "" def key_password = "" def store_file = "" def store_password = "" try { key_alias = YOUR_KEY_ALIAS key_password = YOUR_KEY_PASSWORD store_file = YOUR_KEYSTORE_PATH store_password = YOUR_KEYSTORE_PASSWORD } catch (Exception exception) { throw new IllegalStateException('Failed to find key store details. Social Login is disabled'); } android { signingConfigs { config { keyAlias key_alias keyPassword key_password storeFile file(store_file) storePassword store_password } } buildTypes { debug { signingConfig signingConfigs.config // ... } release { signingConfig signingConfigs.config // ... } } } 

You can use below snippet

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_GOOGLE_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if (result.isSuccess()) { // ... } else if (result.getStatus().getStatusCode() == CommonStatusCodes.NETWORK_ERROR) { // No internet connection } else if (result.getStatus().getStatusCode() == CommonStatusCodes.DEVELOPER_ERROR) { // Wrong server OAuth key(server_client_id) } else if (result.getStatus().getStatusCode() == 12501) { // Wrong app signing-certificate fingerprint SHA1 } else { Log.e("Google sign in error", result.getStatus().toString()); } } } 

Note. If you only activated Google login when creating the configuration file, you do not need to add the google-servies.json to your project (creating the file performs the necessary configuration steps).

0
Dec 28 '16 at 10:17
source share

Try the following steps:

  • Clone the following project https://github.com/googlesamples/google-services

  • Follow the instructions at https://developers.google.com/identity/sign-in/android/start

  • Use the web client (automatically created by Google) and add it to requestIdToken (...)

     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestIdToken("YOUR_WEB_API_ID.apps.googleusercontent.com") .build(); 
  • Make sure you are using the same keystore that was added to your Google project. For example, if you used the following command to generate the SHA-1 key

     keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore 
  • Then add the following code to the app / build.gradle file inside android {...} [solved my problem]

     signingConfigs { debug { storeFile file("/home/ashwin/.android/debug.keystore") storePassword "android" keyAlias "androiddebugkey" keyPassword "android" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { signingConfig signingConfigs.debug } } 

Note. Your keyword and keywords must be the same when creating the SHA-1 certificate.

0
Jan 27 '17 at 13:50
source share

1.Save signature in gradle file

 signingConfigs { config { keyAlias 'appalias' keyPassword 'hunter123' storePassword 'hunter123' storeFile file('path/to/keystore.jks') } } 

2.Go to create types in the project structure (in Android Studio) and specify that signedConfigs for "config"

Now clean your project and create it again. It should work.

If the above does not work, then below is the last. . , .

  • apk ( ).
  • , apk ( android).
  • apk .
  • .
  • google. 12501, . gradle.
  • Try again. It should work.
0
10 . '17 12:48
source share

Google -, auth client v2.0

  • Google API

    Android

    2

  • " " β†’ OAuth β†’ -

  • Ok

  • , Android Studio Firebase ( ) google-services.json .

    .

0
23 . '17 0:11
source share

, :

  • , SHA1 SHA1.

  • google-services.json

  • Google

  • my result.isSucces() true

, sha1 sha1 google-services.json

0
25 . '17 9:09
source share

12501 status . SHA-1 APK APK.

  • APK. APK, , SHA-1. /.android/debug.keystore
  • : androiddebugkey
  • storepass keypass: android.
0
27 '17 20:36
source share
  • one
  • 2



All Articles