如何通过用户电子邮件 Firebase android 获取用户 ID? [英] How to get userID by user Email Firebase android?
问题描述
给定一个电子邮件地址,是否可以获取一个人的用户 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 android 获取用户 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!