【问题标题】:What the reason i get isReject() in addOnCompleteListener() Auth Firebase?我在 addOnCompleteListener() Auth Firebase 中得到 isReject() 的原因是什么?
【发布时间】:2016-09-06 13:44:09
【问题描述】:

我检查了所有代码,它与我之前实现的正常工作示例完全相同。问题是 - 每次我在身份验证侦听器中被拒绝。

为了描述我有两个项目:

首先 - 用于测试(我已经使用 Firebase 实现了身份验证并且它正在工作)

第二个 - 我的主要项目(我试图从我的测试项目中实现相同的代码但没有成功)

这是我的代码

用户点击 Google LogIn 按钮,我在

中捕获结果
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == States.GOOGLE_SIGNIN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        googleImplementation.handleSignInResult(result);
    }
}

public void handleSignInResult(GoogleSignInResult result) {
    if (result.isSuccess()) {
        GoogleSignInAccount acct = result.getSignInAccount();
        new FirebaseAuthLogIn(respond).firebaseAuthWithGoogle(acct);
    }
}

public void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    String token = acct.getIdToken();
    AuthCredential credential = GoogleAuthProvider.getCredential(token, null);
    FirebaseAuth.getInstance().signInWithCredential(credential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
               ------>>    respond.isReject();    <-------
                    } else {
                        respond.isSuccessful();
                    }
                }
            });
}

我做错了什么?这不起作用的原因是什么?在测试项目中,它在主项目中完美运行,我一直被拒绝......

如果我忘了添加一些重要的东西,请随时问我。

【问题讨论】:

  • 您是否在 Firebase 控制台中启用 Google 登录?
  • 在下面查看我的答案,如果您遇到任何问题,请告诉我。
  • @VishalPatoliya 是的,我真的忘了在谷歌控制台中启用它。谢谢

标签: java android firebase firebase-authentication


【解决方案1】:

注意:-

请检查您在 Firebase 控制台中是否启用了使用 google 登录的权限!

【讨论】:

    【解决方案2】:

    Use this method which is working for me currently in my project. Make sure to enable sign-in with google in your developer console.

    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
            Log.d("test", "firebaseAuthWithGoogle:" + acct.getId());
    
            AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
            auth.signInWithCredential(credential)
                    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            Log.d("test", "signInWithCredential:onComplete:" + task.isSuccessful());
    
                            // If sign in fails, display a message to the user. If sign in succeeds
                            // the auth state listener will be notified and logic to handle the
                            // signed in user can be handled in the listener.
                            if (!task.isSuccessful()) {
                                Log.w("test", "signInWithCredential", task.getException());
                                Toast.makeText(MainActivity.this, "Authentication failed.",
                                        Toast.LENGTH_SHORT).show();
                            } else {
                                startActivity(new Intent(MainActivity.this, OtherActivity.class));
                                finish();
                                overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
                            }
                            // ...
                        }
                    });
    }
    

    Call that function inside handleSignInResult method.

    if (result.isSuccess()) {
                // Signed in successfully, show authenticated UI.
                GoogleSignInAccount acct = result.getSignInAccount();
                firebaseAuthWithGoogle(acct);
                //mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
                //updateUI(true);
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-10
      • 2019-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多