0

如何從FirebaseUser獲取Google帳戶的名稱和個人資料照片?Firebase身份驗證中的用戶配置文件信息null使用Google登錄

我正在關注集成Google登錄和Firebase身份驗證的Firebase Android documentation。當我使用Google登錄進行身份驗證時,我可以從GoogleSignInAccount#getPhotUrl()GoogleSignInAccount#getDisplayName()獲取用戶個人資料信息。

我可以登錄到火力地堡與FirebaseAuth.getInstance().signInWithCredential(account)(其中account是相同的認證GoogleSignInAccount對象,但我得到空值從火力地堡側的用戶配置文件信息

谷歌登錄的結果回調:。

GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
if (result.isSuccess()) { 
    GoogleSignInAccount account = result.getSignInAccount(); 
    account.getEmail(); // Valid email 
    account.getDisplayName(); // Valid name 
    account.getPhotoUrl(); // Valid Uri 
    firebaseAuthWithGoogle(account); 
} 

谷歌登錄功能+火力地堡驗證:

private void firebaseAuthWithGoogle(GoogleSignInAccount account) { 
    AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null); 
    mAuth.signInWithCredential(credential) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        if (task.isSuccessful()) { 
         // Sign in success, update UI with the signed-in user's information 
         Log.d(TAG, "signInWithCredential:success"); 
         FirebaseUser user = mAuth.getCurrentUser(); 
         user.getEmail(); // Valid email 
         user.getDisplayName(); // null 
         user.getPhotoUrl(); // null 
        } 
       } 
      }); 
} 
+0

爲什麼你需要從'FirebaseUser'對象中取得這些值而不是'GoogleSignInAccount'? –

+0

@AlexMamo像[FirebaseUI for Android](https://github.com/firebase/FirebaseUI-Android)這樣的庫不公開Goog​​le Sign-In類,並且FirebaseUser是獲取配置文件信息的方式。 –

回答

0

我能解決我的proble通過使用新的Firebase項目和新的Gmail帳戶。

相關問題