Why do I get com.google.android.gms.common.api.ApiException: 10:?

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class); //exception is here

        // Signed in successfully, show authenticated UI.
        System.out.println("google token ---> " + account.getIdToken());
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information about this error.
        e.printStackTrace();
    }
}

Solution 1:

Quoting the documentation:

Certain Google Play services (such as Google Sign-in and App Invites) require you to provide the SHA-1 of your signing certificate so we can create an OAuth2 client and API key for your app.

If you are using Firebase and try on the debug app :

1. First, get your SHA-1 debug key :

  1. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
  2. Click on Tasks
  3. Click on Android
  4. Double Click on signingReport (You will get SHA-1 and MD5)

2. Add new credentials to API Console

  1. Go here https://console.developers.google.com/apis/credentials
  2. Create new OAuth Client ID
  3. Name : Android client (for debug) (example)
  4. Signing-certificate fingerprint : Copy paste you SHA-1 debug key
  5. Put your package name then saved

3. Add your key to your Firebase project :

  1. Go to Project settings -> SHA certificate fingerprints -> Add SHA-1 key of debug app.

  2. Then you can update your google-services.json file in your Android project.

It's works for me.

Solution 2:

This status code means that you are providing unknown server client id. In https://console.developers.google.com/apis/credentials in your project you might need to generate: OAuth client ID -> Web Application and use this web application client id here:

val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(webApplicationClientId)
        .requestEmail()
        .build()