简体   繁体   English

如何从uid Firebase数据库获取电子邮件地址?

[英]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). 我需要从一个用户(不是当前用户)的uid获取电子邮件地址。 My database has one child called "users" and this one has children which keys are the uid of the all the users. 我的数据库有一个称为“用户”的孩子,而这个数据库有一个孩子,哪些键是所有用户的uid。 I need to get the email address of the other users by their uid. 我需要通过其他用户的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. 如果您要使用自己的uid从FirebaseAuth获取用户的电子邮件,则无法从android客户端获取。 Only firebase admin who can get the email of the user from the FirebaseAuth , and android sdk has NO admin permissions. 只有firebase管理员可以从FirebaseAuth获取用户的电子邮件,而android sdk没有管理员权限。 You need to add the email to the Firebase Database in order to get the email of the needed user. 您需要将电子邮件添加到Firebase数据库中,以获取所需用户的电子邮件。

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

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