GoogleSignInAccount帐户= task.getResult(ApiException.class);

时间:2019-07-18 17:25:25

标签: android google-signin googlesigninapi

我正在使用firebase的google登录开发一个登录系统,我已经完成了文档中提到的所有操作,但仍然无法登录。我认为try and catch块中存在问题。代码停止在此行运行,并最终在catch块中。

GoogleSignInAccount account = task.getResult(ApiException.class);

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);

            try {
                // Google Sign In was successful, authenticate with Firebase
                GoogleSignInAccount account = task.getResult(ApiException.class);
                progress.show();
                firebaseAuthWithGoogle(account);

            } catch (ApiException e) {

                // Google Sign In failed, update UI appropriately
                //  Log.w(TAG, "Google sign in failed", e);
                Toast.makeText(this, "Failed Sign in", Toast.LENGTH_SHORT);
                // ...
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

我认为您在使用Firebase Gmail身份验证时错过了一些配置。我在下面提到的Github储存库。这将帮助您使代码正常工作。

Github存储库

Androchef Firebase Auth Login

提交Gmail身份验证提交

Google sign in Added

有关Firebase Google身份验证的博客帖子

Firebase Google Authentication – Example