如何访问另一个 FirebaseUser 的属性?
How to access another FirebaseUser`s properties?
好吧,我可以将当前 FirebaseUser
对象作为 FirebaseAuth.getInstance().getCurrentUser()
访问,然后我可以调用 getPhotoUrl()
或 getDisplayName()
方法。
问题是给了用户UUID,如何访问另一个用户的对象并调用这些方法?
PS:在 android
执行此操作的常用方法是将有关用户的可共享信息存储在 Firebase 数据库中。
firebase.com 上的文档对此有一个很好的例子。请参阅 https://www.firebase.com/docs/android/guide/user-auth.html#section-storing 新的 Firebase 更改的方法仍然相同,但您需要稍微修改一下代码。
我将添加一条注释,我们也需要将此示例添加到新的 Firebase 文档中。
FirebaseUser 有一组固定的基本属性——唯一 ID、主要电子邮件地址、姓名和照片 URL——存储在单独项目的用户数据库中;这些属性可以由用户更新。您不能直接向 FirebaseUser 对象添加其他属性;相反,您可以将其他属性存储在 Firebase 实时数据库中。
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.createUserWithEmailAndPassword("email@example.com", "my pass")
.continueWithTask(new Continuation<AuthResult, Task<Void>> {
@Override
public Task<Void> then(Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = task.getResult().getUser();
DatabaseReference firebaseRef = FirebaseDatabase.getInstance().getReference();
return firebaseRef.child("users").child(user.getUid()).child("phone").setValue("650-253-0000");
} else {
// User creation didn't succeed. Look at the task exception
// to figure out what went wrong
Log.w(TAG, "signInWithEmail", task.getException());
}
}
});
好吧,我可以将当前 FirebaseUser
对象作为 FirebaseAuth.getInstance().getCurrentUser()
访问,然后我可以调用 getPhotoUrl()
或 getDisplayName()
方法。
问题是给了用户UUID,如何访问另一个用户的对象并调用这些方法?
PS:在 android
执行此操作的常用方法是将有关用户的可共享信息存储在 Firebase 数据库中。
firebase.com 上的文档对此有一个很好的例子。请参阅 https://www.firebase.com/docs/android/guide/user-auth.html#section-storing 新的 Firebase 更改的方法仍然相同,但您需要稍微修改一下代码。
我将添加一条注释,我们也需要将此示例添加到新的 Firebase 文档中。
FirebaseUser 有一组固定的基本属性——唯一 ID、主要电子邮件地址、姓名和照片 URL——存储在单独项目的用户数据库中;这些属性可以由用户更新。您不能直接向 FirebaseUser 对象添加其他属性;相反,您可以将其他属性存储在 Firebase 实时数据库中。
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.createUserWithEmailAndPassword("email@example.com", "my pass")
.continueWithTask(new Continuation<AuthResult, Task<Void>> {
@Override
public Task<Void> then(Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = task.getResult().getUser();
DatabaseReference firebaseRef = FirebaseDatabase.getInstance().getReference();
return firebaseRef.child("users").child(user.getUid()).child("phone").setValue("650-253-0000");
} else {
// User creation didn't succeed. Look at the task exception
// to figure out what went wrong
Log.w(TAG, "signInWithEmail", task.getException());
}
}
});