So I'm trying to use Google Sign In Authentication using Firebase as provide by this link : https://firebase.google.com/docs/auth/android/google-signin?hl=en
I followed every single step including putting my SHA-1 Fingerprint into the firebase project. I'm currently on debug mode so I only have one SHA-1 Fingerprint.
Here's my code:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.client_id)) .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(this, gso); mAuth = FirebaseAuth.getInstance(); LinearLayout gLog = (LinearLayout) findViewById(R.id.googleLogin); gLog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { signIn(); } }); } private void signIn() { Intent signInIntent = mGoogleSignInClient.getSignInIntent(); startActivityForResult(signInIntent, RC_SIGN_IN); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { // Google Sign In was successful, authenticate with Firebase GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { // Google Sign In failed, update UI appropriately Log.w("Error", "Google sign in failed", e); // ... } } } private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d("Akun", "firebaseAuthWithGoogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d("MsgFirebase", "signInWithCredential:success"); FirebaseUser user = mAuth.getCurrentUser(); Intent i = new Intent(login_activity.this, main_activity.class); i.putExtra("nama", user.getDisplayName()); i.putExtra("email", user.getEmail()); startActivity(i); } else { // If sign in fails, display a message to the user. Log.w("MsgFirebase", "signInWithCredential:failure", task.getException()); } // ... } }); } And here's the error that I got :
com.google.android.gms.common.api.ApiException: 12500: at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source) at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source) at com.mfs.rumah_duka.login_activity.onActivityResult(login_activity.java:112) at android.app.Activity.dispatchActivityResult(Activity.java:6562) at android.app.ActivityThread.deliverResults(ActivityThread.java:3752) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3799) at android.app.ActivityThread.access$1500(ActivityThread.java:154) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5555) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:118) I tried to check if the resultCode from the SigningIntent is success. It turns our it's not Activity.RESULT_OK. I got the error right after I choose an account on the Sign In window.
Solutions that I've tried :
- Changed web client ID in the Firebase Google Sign In setting to the one from my Oath credential in my Cloud Console
- Updated my gms service library to the latest version (According to Google Sign In error 12500)
- Create an OAuth for Android in my Cloud Console
None of those gave me a solution. I tried to read the documentation as to what error code 12500 means but it seems there's no specific cause. It says that try to use another email and it's still the same.
Does anybody has any solution to this?
