[英]Firebase FirebaseAuth.getInstance().getCurrentUser().getDisplayName() returns null with a certain Gmail address
From the title, you would think that there is a published solution to my problem, but in fact I believe I read everything pertinent to my question, but nothing quite matched up.从标题中,您会认为我的问题有一个已发布的解决方案,但实际上我相信我阅读了与我的问题相关的所有内容,但没有任何内容完全匹配。 Here's what I've got:这是我所拥有的:
First of all, this problem has never happened in my app before today, nor did my sign-in change in any way: same Google sign-in code, same account.首先,这个问题在今天之前我的应用程序中从未发生过,我的登录也没有任何变化:相同的谷歌登录代码,相同的帐户。 Everything the same for the past three months, as long as I've been testing.过去三个月一切都一样,只要我一直在测试。 And, as far as I can tell, the problem only occurs with a single account.而且,据我所知,这个问题只发生在一个帐户上。 When the user begins the sign-in process, they are presented with a choice of accounts to sign in with;当用户开始登录过程时,他们会看到用于登录的帐户选择; in this case, I selected the first user:在这种情况下,我选择了第一个用户:
Next, Google authenticates the user and we arrive here in the code:接下来,谷歌对用户进行身份验证,我们在代码中到达这里:
So the question is, why did Firebase suddenly stop providing the display name (and the photo URL)?所以问题是,为什么 Firebase 突然停止提供显示名称(和照片 URL)? From the first screenshot, it's clear that the user has a specified name and photo.从第一个屏幕截图中,很明显用户具有指定的名称和照片。 Apart from that, FirebaseAuth.getInstance().getCurrentUser().isAnonymous() is false, as expected.除此之外,FirebaseAuth.getInstance().getCurrentUser().isAnonymous() 是假的,正如预期的那样。 Any ideas on why this suddenly broke would be greatly appreciated!任何关于为什么突然破裂的想法将不胜感激!
I solved the problem by simply updating my name and photo URL using UserProfileChangeRequest() and the name and photo URL of my Google account, as suggested here :我只需更新使用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.