[英]How to list users information from firebase on android?
I am working on an Android project. 我正在开发一个Android项目。 There is a users node in my firebase and I want to list some information but I don't want to be read uid. 我的Firebase中有一个users节点,我想列出一些信息,但我不想被读为uid。 I took measures but I didn't read the information which such as,name-surname or status. 我已采取措施,但没有阅读姓名,姓氏或状态等信息。 How can I do it? 我该怎么做? My Database Rules; 我的数据库规则;
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid!=null && $uid === auth.uid",
"name-surname": {
".read": true,
".validate": "newData.isString() && newData.val().length < 30"
},
"status": {
".read": true,
".validate": "newData.isString()&& newData.val().length < 75"
},
"website": {
".read": true,
".validate": "newData.isString()&& newData.val().length < 80"
},
"linkedin": {
".read": true,
".validate": "newData.isString()&& newData.val().length < 80"
},
"github": {
".read": true,
".validate": "newData.isString()&& newData.val().length < 80"
}
}
}
}
The part of my code; 我的代码的一部分;
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
final MembersInfo member = new MembersInfo();
mDatabase.child("users").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Is better to use a List, because you don't know the size
// of the iterator returned by dataSnapshot.getChildren() to
// initialize the array
String nameSurname = dataSnapshot.child("uid").child("name-surname").getValue(String.class);
Toast.makeText(MainActivity.this, nameSurname, Toast.LENGTH_SHORT).show();
member.NameSurname=nameSurname;
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(MainActivity.this, databaseError.toString(), Toast.LENGTH_SHORT).show();
}
});
Knowing a user's UID is not a security risk. 知道用户的UID 不会带来安全风险。 See my explanation here: Firebase - Is auth.uid a shared secret? 在这里查看我的解释: Firebase-auth.uid是共享的机密吗?
That said, there are plenty of good reasons to only expose a subset of user profiles in your app. 也就是说,有很多充分的理由只公开应用程序中的一部分用户个人资料。 To do this, you'll have to separate the subset into a separate top-level list. 为此,您必须将子集分成单独的顶层列表。 For example, to allow a list of just the user names without sharing the other info: 例如,要允许仅列出用户名而不共享其他信息:
usernames
"209103": "Frank van Puffelen"
"7174606": "oguzkaganeren"
To be able to read this list, you will need to grant access on /usernames
. 为了能够阅读此列表,您将需要授予对/usernames
访问权限。 So this will still share the UIDs. 因此,这仍将共享UID。
For more examples, see: 有关更多示例,请参见:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.