简体   繁体   English

Firebase:如何获取其他用户的uid?

[英]Firebase : How to get other user's uid?

I've made an chat app just for me and my friend. 我已经为我和我的朋友制作了一个聊天应用程序。

When I message them, I want to store their Uid . 当我向他们发送消息时,我想存储他们的Uid

How do I do that ? 我怎么做 ? Also mention if its needed to reconstruct the entire structure. 还要提及是否需要重建整个结构。

I have thought of String[] uidList = DatabaseReference.child("Users").getKey(); 我想到过String[] uidList = DatabaseReference.child("Users").getKey();

The Messages are not created yet. 消息尚未创建。 I want to create them with friend_user_id which I can't retrieve at this moment. 我想使用目前无法检索的friend_user_id创建它们。

Below is how I want My Firebase Database structure to look like this : 以下是我希望我的Firebase数据库结构如下所示的方式:

app-id:

    Users:
        my_user_id:
            name:"Me"
            last_seen:"MyLastSeenTimeValue"

        friend_user_id:
            name:"Friend"
            last_seen:"FriendLastSeenTimeValue"

    Messages:

        my_user_id:
            friend_user_id:(How to retrieve this ?)
                random_msg_id_1:
                    text:"Hi"
                    msg_type:"text"
                    time:"msgTime"

                random_msg_id_2:
                    text:"Hello"
                    msg_type:"text"
                    time:"msgTime"

        friend_user_id:(How to retrieve this ?)
            my_user_id:
                random_msg_id_1:
                    text:"Hi"
                    msg_type:"text"
                    time:"msgTime"

                random_msg_id_2:
                    text:"Hello"
                    msg_type:"text"
                    time:"msgTime"

Not sure about the Json output but as a guess, it should be something like following codes: 不确定Json输出,但是作为猜测,它应该类似于以下代码:

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
       myRef.child("Messages").child("my_user_id").addValueEventListener(new ValueEventListener() {
                     @Override
                     public void onDataChange(DataSnapshot dataSnapshot) {

                        for(DataSnapshot item_snapshot:dataSnapshot.getChildren()) {

                        // get the data here and loop through the friend_user_id to get the nodes like following
                        Log.d("User id ", item_snapshot.toString());

                    }
                  }

            @Override
             public void onCancelled(DatabaseError databaseError) {
                     // handle error
              }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Firebase从实时数据库获取其他用户的uid - Android Firebase get other user's uid from realtime database 如何从android上的firebase获取用户uid? - How to get user uid from firebase on android? 在Android中,在Firebase中获取最近创建的用户的UID - In Android, get recently created user's UID in Firebase 如何使用Firebase电子邮件/密码身份验证获取UID并添加用户信息 - How to get UID and add user information with Firebase email/password authentication 如何获取通过google登录的用户的firebase UID? - how to get the firebase UID of the user who logged in via google? 如何在 Cloud Functions 存储触发器中获取经过身份验证的 Firebase 用户的 uid - How to get the uid of the authenticated Firebase user in a Cloud Functions storage trigger 获取其他用户的UID Firebase android - get UID of other users Firebase android 如何在Firebase for Android中使用身份验证UId从用户节点获取用户信息? - How to get user information from user node using authentication UId in firebase for android? 如何匹配存储在 Firestore 的 Firebase 安全规则内的文档字段中的用户 uid - How to match a user's uid stored in document field inside Firebase security rule for Firestore 如何从 Flutter 中的 Firebase 获取 uid? - How to get uid from Firebase in Flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM