Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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

  • Made sure oauth client id is present in dev console with correct SHA-1 fingerprint from ~/.android/debug.keystore as suggested in other posts.

  • Using latest play services 49 and in build.gradle at app level: implementation 'com.google.android.gms:play-services-auth:16.0.1'

  • Using below in project level build.gradle:

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);
          }
        }
      });
  }
}
like image 232
cool_stuff_coming Avatar asked Dec 04 '22 19:12

cool_stuff_coming


1 Answers

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
like image 151
azwar_akbar Avatar answered Dec 06 '22 10:12

azwar_akbar