简体   繁体   English

如何在Android上从Firebase列出用户信息?

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

相关问题 如何列出Android(Firebase)中的注册用户名? - How to list the registered users names in Android (Firebase)? 如何从 Android 上的 firebase 获取标记信息? - How to get the information of a marker from firebase on Android? 如何从Firebase数据库读取并将信息存储在列表视图中? Android的 - How can I read from a firebase database and store the information within a list view? Android 如何从Firebase数据库读取用户信息并在Android App中显示为列表 - How to a read user Information from Firebase database and display as a List in Android App 如何从 Android 中的 Firebase 实时数据库接收特定信息? - How to receive specific information from Firebase Realtime db in Android? 如何从用户名列表中为Firebase中的用户提供唯一的用户名 - How to give unique usernames from a list of usernames to the users in the firebase 如何从 Firebase 实时数据库中获取用户列表? - How to get the list of users from Firebase RealTime database? 如何使用Firebase查询中的信息填充Android ListView - How to populate Android ListView with information from Firebase query 如何从Android App删除Firebase身份验证用户? - How to delete firebase Authentication Users from Android App? 如何从Android中的Firebase获取List的值? - How to get values of List from Firebase in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM