为什么我得到 com.google.android.gms.common.api.ApiException: 10:? [英] 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();
}
}
推荐答案
引用文档:
某些 Google Play 服务(例如 Google 登录和应用邀请)要求您提供签名证书的 SHA-1,以便我们可以为您的应用创建 OAuth2 客户端和 API 密钥.
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.
如果您正在使用 Firebase
并尝试使用 调试应用
:
If you are using Firebase
and try on the debug app
:
1.首先,获取您的 SHA-1
调试密钥:
1. First, get your SHA-1
debug key :
- 点击
Gradle
(从右侧面板,你会看到Gradle Bar) - 点击
任务
- 点击
Android
- 双击
signingReport
(您将获得SHA-1
和MD5
)
- 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.向 API 控制台添加新凭据
- 转到这里https://console.developers.google.com/apis/credentials
- 创建新的
OAuth 客户端 ID
- 名称:
Android 客户端(用于调试)
(示例) - 签名证书指纹:复制粘贴你
SHA-1
调试密钥 - 输入你的包名然后保存
3.将您的密钥添加到您的 Firebase
项目:
3. Add your key to your Firebase
project :
转到
项目设置
->SHA 证书指纹
-> 添加调试应用的SHA-1
密钥.
Go to
Project settings
->SHA certificate fingerprints
-> AddSHA-1
key of debug app.
然后您可以更新您的 Android 项目中的 google-services.json
文件.
Then you can update your google-services.json
file in your Android project.
它对我有用.
这篇关于为什么我得到 com.google.android.gms.common.api.ApiException: 10:?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!