Reputation: 453
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);
}
}
});
}
}
Upvotes: 4
Views: 15885
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
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:-
delete the debug.keystore file. The file is stored in C:\Documents and Settings<user>.android\ on Windows
Run your app first from your IDE
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
update your SHA 1 in firebase console
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
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):
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
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
Reputation: 83
I was using Android simulator while I was searching for the solution of this error.Things I tried are as follows:
But this above methods didnt worked until I switched to a physical android device from android simulator. Hope this answer might help someone.
Upvotes: 0
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
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
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:
Upvotes: 15
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
Upvotes: 1
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