FirebaseUser 的个人资料未更新 [英] FirebaseUser's profile is not updated

查看:15
本文介绍了FirebaseUser 的个人资料未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android 上使用 Firebase 身份验证.

I use Firebase Auth on Android.

我的登录流程工作正常,但我无法更新用户名 &profileUrl 紧随其后.

My signin flow works fine but I can't update username & profileUrl right after.

public void test() {
    String username = "test username";
    Uri avatarUri = Uri.parse("http://www.pixelstalk.net/wp-content/uploads/2016/08/Wonderful-Random-Background.jpg");
    UserProfileChangeRequest.Builder builder = new UserProfileChangeRequest.Builder();
    builder.setDisplayName(username);
    builder.setPhotoUri(avatarUri);

    Log.d("UPDATE PROFILE", "user exists=" + (firebaseAuth.getCurrentUser() != null ? "YES" : "NO"));
    Log.d("UPDATE PROFILE", "user anonymous=" + (firebaseAuth.getCurrentUser().isAnonymous() ? "YES" : "NO"));
    firebaseAuth.getCurrentUser().updateProfile(builder.build()).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                if (firebaseAuth.getCurrentUser().getDisplayName() != null) {
                    Log.d("UPDATE PROFILE", "username=" + firebaseAuth.getCurrentUser().getDisplayName());
                } else {
                    Log.d("UPDATE PROFILE", "username=NULL");
                }
                if (firebaseAuth.getCurrentUser().getPhotoUrl() != null) {
                    Log.d("UPDATE PROFILE", "photoUrl=" + firebaseAuth.getCurrentUser().getPhotoUrl().toString());
                } else {
                    Log.d("UPDATE PROFILE", "photoUrl=NULL");
                }
            } else {
                Log.e("UPDATE PROFILE", task.getException().getMessage());
            }
        }
    });

}

我尝试了上面的测试方法,这是我的输出

I tried the test method above and this is my output

更新个人资料:用户存在=是

UPDATE PROFILE: user exists=YES

更新个人资料:用户匿名=NO

UPDATE PROFILE: user anonymous=NO

更新个人资料:用户名=NULL

UPDATE PROFILE: username=NULL

更新个人资料:photoUrl=NULL

UPDATE PROFILE: photoUrl=NULL

我不明白为什么即使使用isSuccessful()"我的 currentUser 也没有更新?结果

I don't understand why my currentUser is not updated even with a "isSuccessful()" result

推荐答案

这是 Firebase 最新版本 (9.8.0) 中的一个已知问题.根据此处,这是一个已知问题.现在唯一的临时修复是将所有内容回滚到 9.6.1 版.

This is a known issue in the latest release of Firebase (9.8.0). It's a known issue according to here. The only temp fix right now is to rollback everything to version 9.6.1.

将应用的 gradle 依赖项更改为 Firebase 组件的这个(这只是一个临时修复,如果在新版本中使用某些东西,它可能会破坏其他东西):

Change your gradle dependencies for the app to this for Firebase components (this is just a temp fix, and it could break something else if using something in new version):

compile 'com.google.android.gms:play-services-auth:9.6.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.google.firebase:firebase-auth:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'

将您的 Grandle 中匹配的那些更改为上面指定的版本.

Change those matching ones in your grandle to the versions specified above.

这篇关于FirebaseUser 的个人资料未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆