添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to integrate Google Sign In into my app. I don't have a back-end server, I am just getting the details of the logged on Google Account to my app.

I first tried it by using Google Sign In Example but I got an error (No code changes made except for printing the stacktrace below). I just used the example SignInActivity as I don't have a back-end server.

 Exception com.google.android.gms.common.api.ApiException: 12500: 
 at com.google.android.gms.common.internal.zzb.zzz(Unknown Source)
 at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)
 at com.ewise.android.api.MainActivity.onActivityResult(SignInActivity.java:89)     at android.app.Activity.dispatchActivityResult(Activity.java:7010)
 at android.app.ActivityThread.deliverResults(ActivityThread.java:4187)
 at android.app.ActivityThread.handleSendResult(ActivityThread.java:4234)
 at android.app.ActivityThread.-wrap20(ActivityThread.java)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1584)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:154)
 at android.app.ActivityThread.main(ActivityThread.java:6316)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
 public class SignInActivity extends AppCompatActivity implements
         View.OnClickListener {
     private static final String TAG = "SignInActivity";
     private static final int RC_SIGN_IN = 9001;
     private GoogleSignInClient mGoogleSignInClient;
     private TextView mStatusTextView;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         // Views
         mStatusTextView = findViewById(R.id.status);
         // Button listeners
         findViewById(R.id.sign_in_button).setOnClickListener(this);
         findViewById(R.id.sign_out_button).setOnClickListener(this);
         findViewById(R.id.disconnect_button).setOnClickListener(this);
         // [START configure_signin]
         // Configure sign-in to request the user's ID, email address, and basic
         // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
         GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                 .requestEmail()
                 .build();
         // [END configure_signin]
         // [START build_client]
         // Build a GoogleSignInClient with the options specified by gso.
         mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
         // [END build_client]
         // [START customize_button]
         // Set the dimensions of the sign-in button.
         SignInButton signInButton = findViewById(R.id.sign_in_button);
         signInButton.setSize(SignInButton.SIZE_STANDARD);
         signInButton.setColorScheme(SignInButton.COLOR_LIGHT);
         // [END customize_button]
     @Override
     public void onStart() {
         super.onStart();
         // [START on_start_sign_in]
         // Check for existing Google Sign In account, if the user is already signed in
         // the GoogleSignInAccount will be non-null.
         GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
         updateUI(account);
         // [END on_start_sign_in]
     // [START onActivityResult]
     @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
         if (requestCode == RC_SIGN_IN) {
             // The Task returned from this call is always completed, no need to attach
             // a listener.
             Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
             handleSignInResult(task);
     // [END onActivityResult]
     // [START handleSignInResult]
     private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
         try {
             GoogleSignInAccount account = completedTask.getResult(ApiException.class);
             // Signed in successfully, show authenticated UI.
             updateUI(account);
         } catch (ApiException e) {
             // The ApiException status code indicates the detailed failure reason.
             // Please refer to the GoogleSignInStatusCodes class reference for more information.
             Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
             e.printStackTrace();
             updateUI(null);
     // [END handleSignInResult]
     // [START signIn]
     private void signIn() {
         Intent signInIntent = mGoogleSignInClient.getSignInIntent();
         startActivityForResult(signInIntent, RC_SIGN_IN);
     // [END signIn]
     // [START signOut]
     private void signOut() {
         mGoogleSignInClient.signOut()
                 .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                     @Override
                     public void onComplete(@NonNull Task<Void> task) {
                         // [START_EXCLUDE]
                         updateUI(null);
                         // [END_EXCLUDE]
     // [END signOut]
     // [START revokeAccess]
     private void revokeAccess() {
         mGoogleSignInClient.revokeAccess()
                 .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                     @Override
                     public void onComplete(@NonNull Task<Void> task) {
                         // [START_EXCLUDE]
                         updateUI(null);
                         // [END_EXCLUDE]
     // [END revokeAccess]
     private void updateUI(@Nullable GoogleSignInAccount account) {
         if (account != null) {
             mStatusTextView.setText(getString(R.string.signed_in_fmt, account.getDisplayName()));
             findViewById(R.id.sign_in_button).setVisibility(View.GONE);
             findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
         } else {
             mStatusTextView.setText(R.string.signed_out);
             findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
             findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
     @Override
     public void onClick(View v) {
         switch (v.getId()) {
             case R.id.sign_in_button:
                 signIn();
                 break;
             case R.id.sign_out_button:
                 signOut();
                 break;
             case R.id.disconnect_button:
                 revokeAccess();
                 break;

From what I read, the issue could be caused by SHA1 Generation.

I followed the complete guide but apparently it's not working.

I copied the SHA1 from gradle signingReport

Variant: debug
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047
----------
Variant: release
Config: none
----------
Variant: debugAndroidTest
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047
----------
Variant: debugUnitTest
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047

what could be the possible cause of this?

Thanks

P.S. Could this be a possible cause?

Google Play services out of date.  Requires 11720000 but found 10932470
                Hi @Dilip I literally used this :) github.com/googlesamples/google-services/tree/master/android/…. Updated it anyway
– Aaron
                Dec 4, 2017 at 12:17
                So what happen you get same error or anything else happen.one thing please make one more time SHA1 manually and put at developer console against your APP and cross check package name  and download google-services.json file  and put at app level.
– Dilip
                Dec 4, 2017 at 12:23
                Yes @Dilip I get the same error. I crossed checked package name. I  even tried using another keystore but the result is the same.
– Aaron
                Dec 4, 2017 at 12:31
                You need to make code changes to get your API key. And yes, you should update the play services
– OneCricketeer
                Dec 4, 2017 at 12:43

Error PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 12500: , null)

This 12500 Error can be solved by adding a support email address to your project in project settings. Open link https://console.firebase.google.com/

Select Your project and open settings tab.

Provide a valid support email and restart your application now.

Thanks man! This error is pretty cryptic, it can mean any of the stuff that are mentioned in the answers here. My problem was this one :( – Billda May 29, 2019 at 10:11 I did everything mentioned in the developer console developers.google.com/identity/sign-in/android/sign-in and after spending a day on trying to put SHA-1 fingerprint and all this was the problem. You helped. Thanks a lot! – class Android Jul 2, 2019 at 18:55 @FazalJarral There is a settings icon at the top left next to title Project Overview click on that and select Project settings in the general tab you can find this Public settings option. – Swaroop Maddu Mar 22, 2020 at 5:07

Check if SHA-1 fingerprints are added to the firebase project settings. If not,find SHA-1 fingerprint using

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

Also, find the SHA-1 fingerprint of release key using

keytool -list -v -keystore <keystore path>

Remove <keystore path> with the path of the key store.

Then add both SHA-1 fingerprints to firebase projects settings.

NB: Don't forget to replace google-services.json with updated google-services.json with new fingerprints. I lost two days on that.

While debug

Android studio automatically generate ~/.android/debug.keystore on first debug build and use it to sign the app.

To get the SHA-1 run (password android) (doc):

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

This SHA-1 should be added to the app settings at firebase to allow usage of google sign in capabilities while testing debug build.

Guessed it (similarity in code and serverless). Firebase project is also connected to the GCP console. We can also change fingerprints in GCP credentials. – Niyas Nazar Oct 27, 2018 at 7:04 Go to console.developers.google.com/apis/credentials .Add new credential (O Auth Client) with SHA key. (Firebase automatically does this for our firebase projects) – Niyas Nazar Nov 6, 2018 at 13:36 The google-services.json file can be found in the app directory inside your project. (Go through Finder / File Explorer) – Mehul Tandale Nov 13, 2018 at 8:37 good and straight forward answer, Just configured my gmail account and bam it does the rest – Ajeett Jun 5, 2020 at 6:38 "for error 12500 You need to add support gmail in settings of firebase only and for error 10 add ssh fingerprint in firebase console as you see in picture" This really helped. I was getting 12500, applied SHA1 fingerprint and it still wasn't working. Adding the SUPPORT EMAIL helped. Thanks! – class Android Aug 27, 2020 at 9:58 @Vijay I have a same issue but adding email address does not solve my problem stackoverflow.com/questions/64587610/… Please help – Viktor Apoyan Nov 3, 2020 at 10:34

Support email and also all project and privacy links are necessary for Google SignIn to work, otherwise it throws 12500.

Set it on https://console.developers.google.com/apis/credentials on the bottom of second tab named "OAuth consent screen" - there you'll find three links that need to be configured.

This is not mentioned ANYWHERE in the Firebase guides.

Thanks, I just added one of the 'authorised domains' to the privacy links and everything worked. You saved me some hours of trial and error 💌 – Coco Jul 15, 2019 at 16:42 On second tab named "OAuth consent screen" - on the bottom of the form you've got three links – zub0r Jul 25, 2019 at 12:14 To set Email and Privacy Policy : Click on "OAuth consent screen" -> Click on "Edit App". Now you can see both options. – Sanjay Kumar Dec 26, 2019 at 12:37 @zub0r's solution regarding project and privacy links should be accepted as the correct answer. – AdamHurwitz Jul 22, 2019 at 19:33 Also all project and privacy links are necessary, otherwise it throws 12500. This is not mentioned anywhere. – zub0r Jul 12, 2019 at 13:16
  • Correct SHA key is saved on Firebase Console.
  • Download the latest google-service.json
  • And Last and most important Save OAuth consent under credentials in google api, OAuth Screen This took a long to figure out. And it worked fine after this.
  • well. this should be the accepted answer for 2019 here. the google strangely "must" update the content inside OAuth Consent – mochadwi Jul 10, 2019 at 19:13

    Seems your SHA1 is overwritten by Google play store. Check in your google play store, launch panel, under app signing, see if google play has an additional SHA1 added.

    And copy that SHA1, add to your relevant place, would do the job.

    oh my god! Thank you for this tip! App Bundles created its own SHA1, so the release keys that are used locally (when generating APKs) isn't the correct one anymore. – Jia Tse Nov 22, 2018 at 6:47

    In my case, the issue was that my emulator did not have Play Store. I have made the emulator (named API 23) through Visual Studio, because I develop using Xamarin.Forms as well, and in Visual Studio's Android Device Manager you can select if your emulator should have Google Play Store.

    Had to create an emulator through Android Studio's AVD and ensure that it had Play Store:

    I think the error came from the Wrong SHA1. Please don't forget that the SHA1 is different between release and debug mode in the android studio. Instead of using keytool to get the SHA1, you can use Gradle project -> Task -> android -> signingReport in the android studio (can open it by menu View -> Toolwindow -> gradle ) to get release and debug SHA1. After that, for easy working, you need to create 2 separate credentials with two SHA1 on google cloud console (google just instruct to create 1 using release SHA1, when we develop it will not work since it uses the debug SHA1).

    I'm using Firebase Authentication. My SHA-1 was indicated correctly, client id was also correct but I still was getting 12500.

    It turned out that my problem was that I didn't indicate Support email in my project settings. (Settings -> General tab -> Your project (Public settings) section).

    Same thing happened for me as well. There is serious documentation issues with google's services. I wish they documented such issues or at least show a user friendly error. – ashish-goel Jun 24, 2019 at 9:27 When a domain is used on the consent screen or in an OAuth client’s configuration, it must be pre-registered here. If your app needs to go through verification, please go to the Google Search Console to check if your domains are authorized. Learn more about the authorized domain limit. anyone knows what to enter here? – Guy Aug 16, 2021 at 13:14

    Go to your project in the Firebase console, open Project Settings, add your SHA certificate fingerprints there. Download the updated google-services.json file and add it to your Projects app folder.

    This worked for me.

    Thanks for this! I also deleted my Android client ID because I thought it's not needed since we only need the web client ID. – zeenosaur Sep 7, 2020 at 13:20

    Getting the debug/release key:

    keytool -exportcert -list -v -alias [your alias] -keystore [path/to/debug or release.keystore]
    

    Make sure to download the updated google-services.json to your app.

    I was failing with GoogleSignInResult.getSuccess() returning false and a code of 12500. Ultimately, it was that someone else had setup my OAuth with their SHA1 instead of my debug key. This fixed it. – Reckless Jan 21, 2019 at 17:35

    I tried all of the answers and still was getting 12500. It turned out that the solution for me was even simpler - my project has User Type set to internal and I was trying to log in with email outside of my company. So if none of the previous answers work for you, check if you have User Type set to internal or external and if you try to log in with acceptable account.

    When your app authenticates with a backend server or accesses Google APIs from your backend server, then you must pass the OAuth 2.0 client ID that was created for your server to the requestIdToken method when you construct the GoogleSignInOptions object, for accessing the user's basic profile information. Also, don't forget to submit the support email in the OAuth consent screen found in the Credentials page in the API Console.

    After I tried all solutions above and nothing has worked. I found that I am requesting scope that is not mentioned in the cloud. These is my code

    final GoogleSignIn googleSignIn = new GoogleSignIn(
        scopes: [
          'https://www.googleapis.com/auth/userinfo.email',
          'https://www.googleapis.com/auth/userinfo.profile',
          'https://www.googleapis.com/auth/openid',
          'https://www.googleapis.com/auth/youtube.force-ssl'
    

    After I removed all scopes, it worked.

    My scopes section was empty:

    Scopes tab can be found here: https://console.cloud.google.com/apis/credentials/consent/edit

    Solution: Before executing ionic cordova build android specify the signing properties

    Step-1: Generate a debug keystore file

    Execute the command

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

    Use password: android

    Step-2: Copy the keystore file(debug.keystore) from ~/.android to platform/android directory of your current project

    Step-3: Create a file named release-signing.properties in the platform/android directory

    Step-4: Add the contents in the file

    storeFile=debug.keystore
    keyAlias=androiddebugkey
    storePassword=android
    keyPassword=android
      

    Note: These are the default values. If you have provided custom alias and password then use them accordingly.

    Step-5: Now build ionic cordova build android

    I experienced the same problem after opening my project on another computer (different Android Studio). In my case, I solved it using the Firebase Assistant, which I had used to setup Firebase initially. Opened the Firebase Assistant (Tools > Firebase) and selecting Authentication > Connect. This reconnected the project to Firebase and updated the configs

    I was stuck in the Google Login issue since 2 week, finally sorted it well .let me explain the reason. The issue was related with firebase. In firebase , they mentioned a field "support email " as optional . But once i added it (any of your personal email) ,the issue sorted and i got the response . If your getting an error as 12501 , then it is related to settings in your google account.

  • Generate Client Id in your Google Project.
  • Provide proper SHA-1 key for that Client Id. (debug / release)
  • Provide proper package name for that Client Id.
  • Make sure you have generated Client Id in strings.xml, google-services.json or credentials.json file.
  • https://developers.google.com/identity/sign-in/android/sign-in follow this api documentation but keep in mind that inside WEB_CLIENT_ID use the value of client id which is generated inside google-services.json file.

    class MainActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFailedListener {
    private val TAG = "JSAGoogleSignIn"
    private val REQUEST_CODE_SIGN_IN = 1234
    private val WEB_CLIENT_ID = "354298333018-XXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"
    private var mAuth: FirebaseAuth? = null
    private var mGoogleApiClient: GoogleApiClient? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var txt_register = findViewById<TextView>(R.id.txt_register)
        txt_register.setOnClickListener {
            var intent = Intent(this@MainActivity, RegisterActivity::class.java)
            finish()
            startActivity(intent)
        val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(WEB_CLIENT_ID)
                .requestEmail()
                .build()
        mGoogleApiClient = GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build()
        mAuth = FirebaseAuth.getInstance()
        sign_in_button.setOnClickListener {
            val intent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient)
            startActivityForResult(intent, REQUEST_CODE_SIGN_IN)
    override fun onConnectionFailed(p0: ConnectionResult) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    private fun updateUI(user: FirebaseUser?) {
        if (user != null) {
            Log.e("Email", "Value" + user.email)
    fun signIn() {
    override fun onStart() {
        super.onStart()
        val currentUser = mAuth!!.currentUser
        updateUI(currentUser)
    public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
        if (requestCode == REQUEST_CODE_SIGN_IN) {
            val result = Auth.GoogleSignInApi.getSignInResultFromIntent(data)
            if (result.isSuccess) {
                // successful -> authenticate with Firebase
                val account = result.signInAccount
                firebaseAuthWithGoogle(account!!)
            } else {
                // failed -> update UI
                updateUI(null)
                Toast.makeText(applicationContext, "SignIn: failed!" + result.status,
                        Toast.LENGTH_SHORT).show()
    private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount) {
        Log.e(TAG, "firebaseAuthWithGoogle():" + acct.id!!)
        val credential = GoogleAuthProvider.getCredential(acct.idToken, null)
        mAuth!!.signInWithCredential(credential)
                .addOnCompleteListener(this) { task ->
                    if (task.isSuccessful) {
                        // Sign in success
                        Log.e(TAG, "signInWithCredential: Success!")
                        val user = mAuth!!.currentUser
                        updateUI(user)
                    } else {
                        // Sign in fails
                        Log.w(TAG, "signInWithCredential: Failed!", task.exception)
                        Toast.makeText(applicationContext, "Authentication failed!",
                                Toast.LENGTH_SHORT).show()
                        updateUI(null)