I was trying to use authentication in android studio see the below code for reference. Image of code
int RC_SIGN_IN = 65;
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);
Log.e("logging task",task.toString());
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
Log.e("result",account.toString());
Log.d("TAG", "firebaseAuthWithGoogle:" + account.getId());
Toast.makeText(SignInActivity.this, "going to signin", Toast.LENGTH_SHORT).show();
firebaseAuthWithGoogle(account.getIdToken());
} catch (ApiException e){
// Google Sign In failed, update UI appropriately
Log.e("TAG", "Google sign in failed", e);
Toast.makeText(SignInActivity.this, "cant", Toast.LENGTH_SHORT).show();
}
}
}
It going in the catch block. Following are the logs:
2022-11-29 20:32:30.133 18877-18877/com.example.mindfull E/logging task: com.google.android.gms.tasks.zzw@1b86be8
2022-11-29 20:32:30.142 18877-18877/com.example.mindfull E/TAG: Google sign in failed
com.google.android.gms.common.api.ApiException: 10:
at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@18.0.1:3)
at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(com.google.android.gms:play-services-auth@@20.4.0:3)
at com.example.mindfull.SignInActivity.onActivityResult(SignInActivity.java:122)
at android.app.Activity.dispatchActivityResult(Activity.java:8110)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I am following this tutorial:https://youtu.be/vcQu0mHv9OM