Google 登录但结果代码为 0

2024-02-17

我想为我的应用程序创建一个 Google 标志,但我的结果代码来自onActivityResult() is 0

In my onCreate()方法我启动功能startSignInIntent()像这样:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //some other stuff
        view.loadUrl(myURL);
        startSignInIntent();
}

这是startSignInIntent()

private void startSignInIntent() {
        GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
                GoogleSignInOptions.DEFAULT_SIGN_IN);
        Intent intent = signInClient.getSignInIntent();
        startActivityForResult(intent, RC_SIGN_IN);
    }

这是onActivityResult()

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d(TAG, "data : " + resultCode + " | " + data  + " || " + RC_SIGN_IN + " ||| " + requestCode);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()) {
                // The signed in account is stored in the result.
                GoogleSignInAccount signedInAccount = result.getSignInAccount();
            } else {
                String message = result.getStatus().getStatusMessage();
                if (message == null || message.isEmpty()) {
                    Toast.makeText(this, "Login failed", Toast.LENGTH_LONG).show();
                }
                new AlertDialog.Builder(this).setMessage(message)
                        .setNeutralButton(android.R.string.ok, null).show();
            }
        }

这是函数中登录的结果onActivityResult()

0 |意图{(有额外内容)}|| 2 ||| 2

After I select an account of the the pop-up where I can choose my account. I get this screen with ok but when I have that the login already failed. See photo: enter image description here


我遇到了同样的错误,requestCode 始终为 0 (RESULT_CANCELED)。

决定是在 firebase 控制台中启用 google 登录。

Firebase 控制台 -> 您的项目 -> 身份验证 -> 提供商 -> Google -> 并将其打开。

就我而言,链接是这样的

https://console.firebase.google.com/u/0/project/ https://console.firebase.google.com/u/0/project/{项目名称}/身份验证/提供商

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Google 登录但结果代码为 0 的相关文章

随机推荐