I'm trying to add sign in with google button to my application. I followed the google documentation. But always the result is given for me is null. Therefore I cannot access result.isSuccess(). It gives com.google.android.gms.auth.UserRecoverableAuthException: BadAuthentication exception. I followed all the steps correctly.
This is the sign in intent.
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, 1);
This is where I receive result
if (requestCode == 1) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
handleSignInResult() method
private void handleSignInResult(GoogleSignInResult result) {
Log.e("Result",result.getStatus().toString());
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
String idToken = acct.getIdToken();
gtoken();
} else {
Toast.makeText(LoginListener.this,"Unsuccessful",Toast.LENGTH_SHORT).show();
}
}
google sign in option
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
I cannot find what is the reason. If you need to know anything please comment. Any help is highly appreciated. Thank you.