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
}
}
});
}
爲什麼你需要從'FirebaseUser'對象中取得這些值而不是'GoogleSignInAccount'? –
@AlexMamo像[FirebaseUI for Android](https://github.com/firebase/FirebaseUI-Android)這樣的庫不公開Google Sign-In類,並且FirebaseUser是獲取配置文件信息的方式。 –