cool_stuff_coming
cool_stuff_coming

Reputation: 453

com.google.android.gms.common.api.ApiException: 12500

This is my first attempt.... trying to find the issue for last 2 days. I am trying to integrate google sign in to android app, however getting below: com.google.android.gms.common.api.ApiException: 12500

Followed the code from: https://firebase.google.com/docs/auth/android/google-signin

buildscript { // ... dependencies { // ... classpath 'com.google.gms:google-services:4.1.0' // google-services plugin } }

public class SignUpActivity extends AppCompatActivity {

private GoogleSignInClient gsc;

private FirebaseAuth firebaseAuth;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);
    GoogleSignInOptions gso = new GoogleSignInOptions
      .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
      .requestIdToken(String.valueOf(R.string.gplus_api_client_id))
      .requestEmail()
      .build();

    gsc = GoogleSignIn.getClient(this, gso);

    //Initialize firebase authentication
    firebaseAuth = FirebaseAuth.getInstance();
  }


  @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);
    }
  }
  private void handleSignInResult(Task < GoogleSignInAccount > completedTask) {
    try {
      //Sign in Successful
      GoogleSignInAccount account = completedTask.getResult(ApiException.class);
      Log.w("SignUpActivity/handleSignInResult", "Trying signing in with Google...  " + account);
      firebaseAuthWithGoogle(account);

      // Signed in successfully, show authenticated UI.

      // Log.w("SignUpActivity/handleSignInResult", "Google sign in successful for account " + 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("SignUpActivity/handleSignInResult", "Google sign in failed with exception: " + e);
    }
  }

  private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
    Log.i("SignUpActivity/firebaseAuthWithGoogle", "Signed in as : " + account.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);

    firebaseAuth.signInWithCredential(credential)
      .addOnCompleteListener(this, new OnCompleteListener < AuthResult > () {
        @Override
        public void onComplete(@NonNull Task < AuthResult > task) {
          if (task.isSuccessful()) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            Log.i("SignUpActivity/firebaseAuthWithGoogle", "Sign in successful for user : " + user);
          } else {
            Log.e("SignUpActivity/firebaseAuthWithGoogle", "User Authentication failed.");
            Snackbar.make(findViewById(R.id.view_signup), "Authentication failed.", Snackbar.LENGTH_SHORT);
          }
        }
      });
  }
}

Upvotes: 4

Views: 15885

Answers (10)

Shahriar Zaman
Shahriar Zaman

Reputation: 938

I faced the same issue today. My app was working fine previously but today I was getting error code 12500. It's not a firebase app. Only Google drive API is used. My app is in testing mode. I tried providing app logo, but it didn't help. I just deleted the old android OAuth2 credential from google cloud console and recreated it again. Now it's working again.

Upvotes: 0

Priyanshu Paliwal
Priyanshu Paliwal

Reputation: 2388

If you are getting platform Exception and this com.google.android.gms.common.api.ApiException: 12500 then don't worry, follow this link I hope your issue will be solved.

Steps:-

  1. delete the debug.keystore file. The file is stored in C:\Documents and Settings<user>.android\ on Windows

  2. Run your app first from your IDE

  3. generate a new debug.keystore file using this command, keytool -list -v -keystore "%USERPROFILE%.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android here USERPROFILE means the name of your PC user name

  4. update your SHA 1 in firebase console

  5. download the updated version of google_service.json file

for reference use this link, https://github.com/flutter/flutter/issues/25640#issuecomment-449589417

Upvotes: 0

ken
ken

Reputation: 2662

For whom that end up in this question, I sure you are stretching your hair right now and keep thinking why is it still doesn't work. Let me share what is work for me.

After you done all this below,but still not get it work(get the all mighty 12500 error):

  1. Check the debug SHA-1 key in Firebase project setting
  2. Updated your google-service.json in your project
  3. Updated your support email in Firebase project
  4. Updated your privacy link,term of service link,Application logo in Oath2 consent page in Google API console
  5. Run in your Android physical device

So:

So basically in your Google API console,you will have 2 OAuth 2.0 Client IDs. You will have 2 item here. When you clicked inside, one will have URI,with your-project.firebaseapp.com set up for you(name is Web client (auto created by Google Service)). DONT USE THAT ONE, instead you another one,which is dont have any URI set up for you(Name is Web client (auto created by Google Sign In)). For some reason,using the second option WORKS.

Hope can help you. Enjoy

Upvotes: 0

Ajay Karthick
Ajay Karthick

Reputation: 1

I ran into the same issue now. After some debugging, I found that I missed enabling the google sign-in method under authentication. After enabling, it works fine.

Upvotes: 0

Harsh
Harsh

Reputation: 83

I was using Android simulator while I was searching for the solution of this error.Things I tried are as follows:

  1. Created SHA1 certificate.
  2. Updated oAuthConsent Screen by adding application logo and support email.

But this above methods didnt worked until I switched to a physical android device from android simulator. Hope this answer might help someone.

  • Happy Learning!

Upvotes: 0

Petros Mosoyan
Petros Mosoyan

Reputation: 258

If after tring all methods mentioned above you still cannot sign in, you also can try run the code on real device. I lost two days tring to sign in with android studio emulator. And if on real device you signed in successfuly then you need to update google play service on you emulator.

Upvotes: 0

Kennan Obura
Kennan Obura

Reputation: 315

I struggled with the same error 12500 for hours. Apparently you need to fill in all the required information (App name, logo, email, authorized domains) on this page https://console.developers.google.com/apis/credentials on OAuth consent screen Tab

Upvotes: 1

azwar_akbar
azwar_akbar

Reputation: 1651

I have this problem. And already solved it. Both SHA1 debug and relase already added to Firebase console, but still did not work. Also I try to only put SHA1 debug and still did not work. After so many try and error I solved it by completing info of "oAuth consent screen" from Credential menu, here is the steps:

  1. Sign in to Google Console Cloud
  2. Select your current project related with current Firebase project
  3. Navigate to API & Services
  4. Click Credential menu
  5. Click "oAuth consent screen"
  6. Add application logo, Application Homepage link and Application Privacy Policy link. To add both link you can just copy and paste from Authorized domains section from "oAuth consent screen", for example: your-app-abc123.firebaseapp.com

Upvotes: 15

madu_dev
madu_dev

Reputation: 87

Follow the Google developer documentation, In there clearly give instruction step by step how integrate google sign in to Android app.

https://developers.google.com/identity/sign-in/android/start Important

  1. Check you have enable Google plus API in google console.
  2. After configuring your project into Google sing in it should be connected to the firebase. You just want to select your project on the firebase.
  3. Include JSON file into your project explorer.
  4. YOUR_SERVER_CLIENT_ID Check you have given correct sever client id.

Upvotes: 1

Attif
Attif

Reputation: 1150

Basically, the problem is in the SHA1 key put on console please regenerate it and put again properly same project.

1)As the answers, make sure that your actual signed Android apk has the same SHA1 fingerprint as what you specified in the console of your Firebase project's Android integration section (the page where you can download the google-services.json)

2)On top of that go to the Settings of your firebase project (gear icon right to the Overview at the top-left area. Then switch to Account Linking tab. On that tab link the Google Play to your project.

Upvotes: 0

Related Questions