I've tried many solutions mentioned here but I'm still unable to fix this. I'm receiving:
"Google sign in failed. com.google.android.gms.common.api.ApiException: 10"
I've verified my OAuth auto-generated 'web client key' in Google Cloud Console is same as what I'm using in my code. But I'm getting the same error. I've also verified that project name is same in Google Cloud Console and Firebase.
Here's my code:
public class LoginActivity extends Activity {
private GoogleSignInClient mGoogleSignInClient;
private FirebaseAuth mAuth = FirebaseAuth.getInstance();
private static final int RC_SIGN_IN = 1;
static LoginActivity loginActivity;
private FirebaseUser currentUser;
public static LoginActivity getInstance(){
return loginActivity;
}
public FirebaseUser getCurrentUser() {
return currentUser;
}
@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.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
mAuth = FirebaseAuth.getInstance();
View signInButton = findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
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) {
//Here resultCode is 0 & requestCode is 1.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// This line of code is throwing exception.
GoogleSignInAccount account = task.getResult(ApiException.class);
Log.w(TAG, task.getException());
Log.d(TAG, "firebaseAuthWithGoogle:" + account.getId());
firebaseAuthWithGoogle(account.getIdToken());
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e);
}
}
}
I'm following this tutorial from official docs. Any help is appreciated.
P.S. I'm also using Firestore database in the same project. And I've successfully saved the google-services.json in the app's folder.
