2016-09-06 41 views
0

我已經檢查過所有的代碼,並且它與之前實施的正確工作的樣本完全相同。問題是 - 每當我在auth監聽器中被拒絕。我在addOnCompleteListener()Auth Firebase中獲取isReject()的原因是什麼?

爲了說明我有兩個項目:

第一 - 用於測試(其中我已經實現身份驗證與火力地堡,它是工作)

和第二 - 我的主項目(其中沒有成功我試圖實施從我的測試項目相同的代碼)

有我的代碼

用戶化妝點擊谷歌的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(); 
        } 
       } 
      }); 
} 

我在做什麼錯?這是什麼原因不起作用?在測試項目,它是完美的主要項目,我得到拒絕所有的時間...

如果我忘了添加一些重要的東西填寫免費問我。

+1

您需要登錄後才能使用谷歌在Firebase控制檯中啓用? –

+0

查看下面的答案,讓我知道你是否面臨任何問題。 –

+0

@VishalPatoliya是的,我真的忘了在谷歌控制檯中啓用它。謝謝 –

回答

2

注: -

請檢查您的許可,在火力控制檯登錄與谷歌的啓用或不!

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); 
     } 
相關問題