在Android上检索用户数据Firebase [英] Retrieve User Data Firebase on Android
问题描述
有没有办法从一个特定的用户通过身份验证通过Firebase身份验证数据?
例如检索像名称,照片等信息。 p>
在此先感谢。
这是更多的iOS的答案,我给了此处
Firebase为使用FIRAuth Clases / API的用户提供身份验证
然而,无法使用 Firebase数据库等自定义字段对其进行编辑。
要允许用户自定义字段,您需要在用户的身份验证中使用相同的唯一 uid
来复制数据库中的用户。就像这样
FirebaseUser user = FirebaseAuth.getInstance()。getCurrentUser();
if(user!= null){
//用户登录
String name = user.displayName;
String email = user.email;
字符串photoUrl = user.photoURL;
String uid = user.uid;
FirebaseDatabase数据库= FirebaseDatabase.getInstance();
String key = database.getReference(users)。push()。getKey();
Map< String,Object> childUpdates = new HashMap<>();
childUpdates.put(uid,uid);
childUpdates.put(name,name);
//这里的其他属性
database.getReference(users)。updateChildren(childUpdates,new DatabaseReference.CompletionListener(){
@Override
public void onComplete (DatabaseError databaseError,DatabaseReference databaseReference){
if(databaseError == null){
}
}
});
$ / code>
我们把它推到 users
终点在我们的数据库和 uid
键由以下行 / users / \(key)
现在,您可以通过查询代码中的任何位置来检索数据库中的用户详细信息。
Is there a way to retrieve data from a specific user who is authenticated via firebase through ID?
For example to retrieve information like name, photo etc.
Thanks in advance.
This is more of a port of the iOS answer i have given here
Firebase provides authentication for users using the FIRAuth Clases/API
However they can't be edited with custom fields like the Firebase Database.
To allow custom fields for user, you need to duplicate users in the Database with the same unique uid
you receive in the auth of the user. Something like this
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// User is signed in
String name = user.displayName;
String email = user.email;
String photoUrl = user.photoURL;
String uid = user.uid;
FirebaseDatabase database = FirebaseDatabase.getInstance();
String key = database.getReference("users").push().getKey();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put( "uid", uid);
childUpdates.put( "name", name);
// other properties here
database.getReference("users").updateChildren(childUpdates, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if (databaseError == null) {
}
}
});
}
We push it at the users
end point in our db and with the uid
key by the following line /users/\(key)
.
Now you can retrieve users detail from your database by querying anywhere in your code.
这篇关于在Android上检索用户数据Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!