如何通过用户电子邮件Firebase Android获取用户ID? [英] How to get userID by user Email Firebase android?

查看:159
本文介绍了如何通过用户电子邮件Firebase Android获取用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个电子邮件地址,是否可以获取某人的用户ID?例如,

Given a email address, is it possbile to get userID of a person? For example,

如果我的可变电子邮件中包含该人的电子邮件.我可以通过类似的方式获取他们的ID

If I have a variable email that has email of the person. Can I get their ID by doing something like

String userID = mAuth.DatabaseReference.getuID.(email);

抱歉,这是一个愚蠢的问题.

Sorry if this a stupid question.

注意,我正在寻找一个不是当前用户的人的ID.所以我不能使用FirebaseUser user = mAuth.getCurrentUser();

note, I am looking to get ID of a person who is not the current user. So I can't use FirebaseUser user = mAuth.getCurrentUser();

我的数据库结构看起来像这样,所以ID已经存储在数据库中了.我只需要一种获取方法(在下面显示的图中,我没有电子邮件字段,但是如果有人想知道-_-,我将添加一个电子邮件字段.)

The structure of my database looks like this, so the ID will be stored in database already. I just need a way of getting it (In the diagram presented below I don't have a field of email but I will be adding one, incase anyone was wondering -_-).

此外,如果可能的话,我想根据他们的电子邮件或通过ID获得ID后获得他们的个人资料图片.

Also, if possible, I would like to get their profile image either based on their email or once I have gotten the id, through ID.

推荐答案

如果要在受信任的服务器上通过电子邮件查找用户,则可以使用Firebase Admin SDK.从有关检索用户数据的文档:

If you want to look up a user by their email on a trusted server, you can use the Firebase Admin SDK. From the documentation on retrieving user data:

admin.auth().getUserByEmail(email)
  .then(function(userRecord) {
    // See the tables above for the contents of userRecord
    console.log("Successfully fetched user data:", userRecord.toJSON());
  })
  .catch(function(error) {
    console.log("Error fetching user data:", error);
  });

用于Firebase身份验证的客户端SDK仅提供对当前已身份验证用户的配置文件的访问.他们没有提供通过电子邮件地址查找用户的方法.要允许客户端查找,通常的方法是将UID-by-email-address存储在数据库中:

The client SDKs for Firebase Authentication only provide access to the profile of the currently authenticated user. They don't provide a way to look up a user by their email address. To allow client-side lookup, the common way to do so is to store the UID-by-email-address in the database:

"emailToUid": {
    "SumOne@domain,com": "uidOfSumOne",
    "puf@firebaseui,com": "uidOfPuf"
}

通过此简单列表,您可以从以下位置通过编码的电子邮件地址查找UID:

With this simple list, you can look up the UID by the encoded email address from:

ref.child("emailToUid").child("SumOne@domain,com").addSingleValueEventListener(...

另请参阅:

  • Firebase Authentication Service - lookup uid from email without login
  • Add Extra Details on Firebase User Table
  • How to get authenticated users from firebase database?

这篇关于如何通过用户电子邮件Firebase Android获取用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆