简体   繁体   中英

How to get the email address from uid Firebase database?

I need to get the email address from uid of one user (not the current user). My database has one child called "users" and this one has children which keys are the uid of the all the users. I need to get the email address of the other users by their uid.

看数据库结构

String uidReceiver = "B53Bk4dtHjZ6a3ZjoO2cEowEf4w2";
DatabaseReference usersRef;
usersRef = FirebaseDatabase.getInstance().getReference().child("users");

// To get the email address of the current user
FirebaseUser userSender = FirebaseAuth.getInstance().getCurrentUser();
String emailSender = userSender.getEmail();    

usersRef.child(uidReceiver).addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (dataSnapshot.exists()) 
                    {
                        // How can I get the email address of uidReceiver
                    }
                }

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

Thanks!

If you mean that you want to get the email of the user from FirebaseAuth using his uid, then it's not possible from android client. Only firebase admin who can get the email of the user from the FirebaseAuth , and android sdk has NO admin permissions. You need to add the email to the Firebase Database in order to get the email of the needed user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM