簡體   English   中英

Firebase FirebaseAuth.getInstance().getCurrentUser().getDisplayName() 使用某個 Gmail 地址返回 null

[英]Firebase FirebaseAuth.getInstance().getCurrentUser().getDisplayName() returns null with a certain Gmail address

從標題中,您會認為我的問題有一個已發布的解決方案,但實際上我相信我閱讀了與我的問題相關的所有內容,但沒有任何內容完全匹配。 這是我所擁有的:

首先,這個問題在今天之前我的應用程序中從未發生過,我的登錄也沒有任何變化:相同的谷歌登錄代碼,相同的帳戶。 過去三個月一切都一樣,只要我一直在測試。 而且,據我所知,這個問題只發生在一個帳戶上。 當用戶開始登錄過程時,他們會看到用於登錄的帳戶選擇; 在這種情況下,我選擇了第一個用戶:

在此處輸入圖片說明

接下來,谷歌對用戶進行身份驗證,我們在代碼中到達這里:

在此處輸入圖片說明

所以問題是,為什么 Firebase 突然停止提供顯示名稱(和照片 URL)? 從第一個屏幕截圖中,很明顯用戶具有指定的名稱和照片。 除此之外,FirebaseAuth.getInstance().getCurrentUser().isAnonymous() 是假的,正如預期的那樣。 任何關於為什么突然破裂的想法將不勝感激!

我只需更新使用UserProfileChangeRequest()我的名字和照片的URL和我的谷歌帳戶的姓名和照片的URL解決了這個問題,因為建議在這里

    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    sendFirebaseEvent(FIREBASE_GOOGLE_AUTH_EVENT, FIREBASE_GOOGLE_AUTH_KEY, acct.getId());
    // [START_EXCLUDE silent]
    showProgressDialog();
    googleAccount = acct;
    // [END_EXCLUDE]
    final AuthCredential credential = GoogleAuthProvider.getCredential(acct.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
                        sendFirebaseEvent(FIREBASE_GOOGLE_AUTH_EVENT, FIREBASE_GOOGLE_AUTH_RESULT_KEY, "Success");
                        launchNextActivity();
                    } else {
                        // If sign in fails, display a message to the user.
                        sendFirebaseEvent(FIREBASE_GOOGLE_AUTH_EVENT, FIREBASE_GOOGLE_AUTH_RESULT_KEY, task.getException().getMessage());
                        Snackbar.make(findViewById(R.id.main_layout), "Authentication Failed.", Snackbar.LENGTH_SHORT).show();
                        updateUI(null);
                    }

                    // [START_EXCLUDE]
                    hideProgressDialog();
                    // [END_EXCLUDE]
                }
            });
}
private void launchNextActivity() {
    mFirebaseAuth = FirebaseAuth.getInstance();
    FirebaseUser mUser = mFirebaseAuth.getCurrentUser();
    if (mUser.getDisplayName() == null || mUser.getDisplayName().length() == 0) {
        UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                .setDisplayName(googleAccount.getDisplayName())
                .setPhotoUri(googleAccount.getPhotoUrl())
                .build();
        mUser.updateProfile(profileUpdates);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM