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:
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);
}
}
});
}
}
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With