[英]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.