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 :
- Click on
Gradle
(From Right Side Panel, you will see Gradle Bar) - Click on
Tasks
- Click on
Android
- Double Click on
signingReport
(You will getSHA-1
andMD5
)
2. Add new credentials to API Console
- Go here https://console.developers.google.com/apis/credentials
- Create new
OAuth Client ID
- Name :
Android client (for debug)
(example) - Signing-certificate fingerprint : Copy paste you
SHA-1
debug key - Put your package name then saved
3. Add your key to your Firebase
project :
Go to
Project settings
->SHA certificate fingerprints
-> AddSHA-1
key of debug app.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()