为什么我得到 com.google.android.gms.common.api.ApiException: 10:? [英] Why do I get com.google.android.gms.common.api.ApiException: 10:?

查看:40
本文介绍了为什么我得到 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 :

  1. 点击Gradle(从右侧面板,你会看到Gradle Bar)
  2. 点击任务
  3. 点击Android
  4. 双击signingReport(您将获得SHA-1MD5)
  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.向 API 控制台添加新凭据

  1. 转到这里https://console.developers.google.com/apis/credentials
  2. 创建新的 OAuth 客户端 ID
  3. 名称:Android 客户端(用于调试)(示例)
  4. 签名证书指纹:复制粘贴你SHA-1调试密钥
  5. 输入你的包名然后保存

3.将您的密钥添加到您的 Firebase 项目:

3. Add your key to your Firebase project :

  1. 转到项目设置 -> SHA 证书指纹 -> 添加调试应用的SHA-1 密钥.

  1. Go to Project settings -> SHA certificate fingerprints -> Add SHA-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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆