简体   繁体   English

com.google.android.gms.common.api.ApiException: 16:

[英]com.google.android.gms.common.api.ApiException: 16:

I try to learn how i can use google sign in in my android App, but i catch com.google.android.gms.common.api.ApiException: 16 And i can't find on stackoveflow answer, what is it and why i catch it.我尝试学习如何在我的 android 应用程序中使用 google 登录,但我发现com.google.android.gms.common.api.ApiException: 16而且我在 stackoveflow 上找不到答案,它是什么以及为什么我抓住它。 In documentation i read, what it "was canceled by user", but my google account accepted to install apps在我阅读的文档中,它“被用户取消”,但我的谷歌帐户接受安装应用程序

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import android.content.Intent
import com.google.android.gms.tasks.Task
import com.google.android.gms.common.api.ApiException

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

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

        val mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
        val account = GoogleSignIn.getLastSignedInAccount(this)
        if(account != null){
            Log.e("!!!", account.email)
        } else {
            val signInIntent = mGoogleSignInClient.signInIntent
            startActivityForResult(signInIntent, 0)
        }
    }

    public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
        if (requestCode == 0) {
            // The Task returned from this call is always completed, no need to attach
            // a listener.
            val task = GoogleSignIn.getSignedInAccountFromIntent(data)
            handleSignInResult(task)
        }
    }

    private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
        try {
            val account = completedTask.getResult(ApiException::class.java)

            // Signed in successfully, show authenticated UI.
            Log.e("!!!", account.email)
        } catch (e: ApiException) {
            e.printStackTrace()
        }

    }

}

I followed this guide .我遵循了 本指南 Did the configuration of the project.做了项目的配置。 If it's matter, i use VDS for this.如果有关系,我为此使用 VDS。 Account was created in the same place帐户是在同一个地方创建的

Here is stackTrace:这是堆栈跟踪:

com.google.android.gms.common.api.ApiException: 16: 
    at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
    at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)
    at foryou.friendly.alisa.alisa.MainActivity.onActivityResult(MainActivity.kt:47)
    at android.app.Activity.dispatchActivityResult(Activity.java:7124)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4173)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4220)
    at android.app.ActivityThread.-wrap20(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1579)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6228)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)

I had the same problem, start activity result kept coming back with RESULT_CANCELED and errorCode 16. The problem was my client configuration in Google Cloud Platform Console. 我遇到了同样的问题,启动活动结果继续使用RESULT_CANCELED和errorCode 16.问题是我在Google Cloud Platform Console中的客户端配置。 I was using the regular debug and release api key. 我正在使用常规的调试和发布api密钥。 The result came back OK when I used web application as my Google Console configuration. 结果回来后OK ,当我使用的web应用程序 ,我的谷歌控制台配置。

Hope it helps. 希望能帮助到你。

Was having the same problem, turns out I did not set support mail on firebase project settings . 有同样的问题,结果我没有在firebase项目设置上设置支持邮件

If this is the case, firebase will show you edit project settings when trying to enable Google sign in on Firebase Authentication . 如果是这种情况, firebase将在您尝试启用Google登录 Firebase身份验证时显示编辑项目设置 You can copy your client Id from firebase 您可以从firebase复制客户端ID

Maybe a bit late to the party here but after more than 4 hours debugging I realized that: 也许这里的派对有点晚了,但经过4个多小时的调试,我意识到:

1.- Add an Android client with your signing-certificates fingerprints under the OAuth client IDs list. 1.-在OAuth客户端ID列表下添加带有签名证书指纹的Android客户端。 This is mandatory. 这是强制性的。

2.- Add the Web application client ID in your code in case your need to get an id token 2.-在您的代码中添加Web应用程序客户端ID,以防您需要获取id令牌

// ID and basic profile are included in DEFAULT_SIGN_IN
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                            .requestIdToken("YOUR_CLIENT_ID")
                            .requestEmail()
                            .build();

Hope it helps 希望能帮助到你

For me the only thing that worked was to provide 2 oauth client ids . 对我来说唯一有用的是提供2个oauth客户端ID a web application client id AND an android client id Web应用程序客户端ID和Android客户端ID

In my android app i use the client id and client secret of the web application. 在我的Android应用程序中,我使用Web应用程序的客户端ID和客户端密钥。 Even though i don't use the android client id anywhere in my app it is still required. 即使我不在我的应用程序中的任何地方使用Android客户端ID它仍然是必需的。 ie if i delete the oauth android client in the google api console my app stops working EVEN THOUGH i dont use that client id ANYWHERE in my app. 即如果我删除谷歌api控制台中的oauth android客户端我的应用程序停止工作即使我不在我的应用程序任何地方使用该客户端ID。

this makes absolutely no sense to me! 这对我来说绝对没有意义! go figure . 去搞清楚 。 but so far this is the only thing that has worked. 但到目前为止,这是唯一有效的方法。

un-freaking-believable. 未吓坏-可信。

I am developing an Android application using Flutter, tried to integrate Google Sign In and faced the same problem with ApiException: 16 and SIGN_IN_FAILED (instead of RESULT_CANCELED). 我正在使用Flutter开发Android应用程序,尝试集成Google登录并遇到与ApiException相同的问题:16SIGN_IN_FAILED (而不是RESULT_CANCELED)。

Application type on Firebase was set to android. Firebase上的应用程序类型设置为android。

In my case, after many hours of debugging, it turned out to be a wrong SHA-1 problem . 就我而言,经过数小时的调试后,结果证明是一个错误的SHA-1问题

As soon as I extracted the SHA-1 key from my project and updated Firebase console, it worked. 一旦我从项目中提取了SHA-1密钥并更新了Firebase控制台,它就能正常工作。

我使用了一个不同的 oauth id 密钥,这是我从下载项目设置中找到的,并在项目中添加了客户端 3 密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安全网:com.google.android.gms.common.api.ApiException:16: - SAFETYNET : com.google.android.gms.common.api.ApiException: 16: com.google.android.gms.common.api.ApiException: 10 - com.google.android.gms.common.api.ApiException: 10 异常com.google.android.gms.common.api.ApiException:12500 - Exception com.google.android.gms.common.api.ApiException: 12500 com.google.android.gms.common.api.ApiException: 12500 - com.google.android.gms.common.api.ApiException: 12500 是否有人对com.google.android.gms.common.api.ApiException:16有任何想法? - Does anyone have any idea about com.google.android.gms.common.api.ApiException: 16? com.google.android.gms.common.api.ApiException:8: - com.google.android.gms.common.api.ApiException: 8: com.google.android.gms.common.api.ApiException: 10: - com.google.android.gms.common.api.ApiException: 10: 带有com.google.android.gms.common.api.ApiException的Google Awareness API位置:7508 - Google Awareness API Places with com.google.android.gms.common.api.ApiException: 7508 com.google.android.gms.common.api.ApiException:12500,在Google的Android Firebase项目中登录 - com.google.android.gms.common.api.ApiException: 12500, in android firebase project in google sign in Android Google 登录失败 com.google.android.gms.common.api.ApiException: 12500 - Android Google Sign In Failed com.google.android.gms.common.api.ApiException: 12500
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM