简体   繁体   English

在 Firebase 中更新 dislayName 会出现语法错误

[英]Updating dislayName in Firebase gives a syntax error

I am trying to update the displayName with the following code.我正在尝试使用以下代码更新displayName But I get an error saying cannot resolve displayName.但是我收到一条错误消息,说无法解析 displayName。 Looks like it doesn't take {displayName:'test name', photoURL:'url to photo'} as a parameter.看起来它没有将 {displayName:'test name', photoURL:'url to photo'} 作为参数。 I am following the Firebase example and examples I found elsewhere, but can't get it to work.我正在关注 Firebase 示例和我在其他地方找到的示例,但无法使其正常工作。 Thank you for your help.谢谢您的帮助。

currentUser.updateProfile({displayName:"test name",photoURL:"url to photo"}); 

FirebaseUser's updateProfile(UserProfileChangeRequest request) method, takes as an argument an object of type UserProfileChangeRequest. FirebaseUser 的updateProfile(UserProfileChangeRequest request)方法将 object 类型的 UserProfileChangeRequest 作为参数。 So there is no way you can pass two String objects to that method.因此,您无法将两个 String 对象传递给该方法。 To solve this, you should construct that object by calling UserProfileChangeRequest.Builder's setDisplayName(String displayName) and setPhotoUri(Uri photoUri) methods along with build() , a method that returns the exact object that you are looking for.要解决此问题,您应该通过调用 UserProfileChangeRequest.Builder 的setDisplayName(String displayName)setPhotoUri(Uri photoUri)方法以及build()来构建 object,该方法返回您正在寻找的确切 object。 In code it should look like this:在代码中它应该是这样的:

UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
    .setDisplayName("test name")
    .setPhotoUri("url to photo")
    .build();
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
firebaseUser.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {
        if (task.isSuccessful()) {
            Log.d("displayName: ", FirebaseAuth.getInstance().getCurrentUser().getDisplayName());
        }
    }
});

The result in the logcat will the new name: logcat 中的结果将是新名称:

test name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 模拟器在尝试使用 Firestore 时出现 CORS 错误 - Firebase emulator gives CORS error when trying to use Firestore 更新firebase上个版本后,MultiDexApplication启动报错 - After updating firebase last version, MultiDexApplication error started 不是号码未更新为 firebase - not number is not updating with firebase 列出了 Firebase 重定向域,但仍然给出错误与 signInWithRedirect - Firebase redirect domain listed but still gives an error with signInWithRedirect 'firebase init' 给了我一个离子项目的一般错误 - 'firebase init' gives me a generic error on a ionic project 对 firebase 云函数的发布请求给出错误 500 - Post request to the firebase cloud functions gives error 500 尝试部署 Firebase 函数时出现 JSDoc 语法错误 - JSDoc syntax error when trying to deploy Firebase functions 尝试为 Firebase 身份验证启用 Google 登录时出现“更新 Google 时出错”消息 - "Error updating Google" message when trying to enable Google Sign-In for Firebase Authentication 更新到 Firebase 版本 9 onValue 后 React Native memory 泄漏错误 - React Native memory leak error after updating to Firebase version 9 onValue 入口给出 502 错误 - Ingress gives 502 error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM