Firebase通过ID获取用户 [英] Firebase get user by ID

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

问题描述

是否可以根据用户的UID获取用户信息(例如电子邮件,图片)?

Is there a way to get user information (like email, picture) based on its UID?

我的意思不是当前登录的用户,而是其他任何用户.

I mean not for the currently logged user, but any other user.

推荐答案

如果使用的是Firebase提供的身份验证方法,则不能,只能从当前会话/用户那里获取它,并且如果需要查询稍后再将其保存在自己的数据存储中.

If you're using the authentication methods provided by Firebase, then no, you can only get it from the current session/user, and if you need to query for it later then you need to save it in your own datastore.

通常,我要做的是在身份验证更改时加载用户数据,如果不存在,那么我将保存一个新对象(使用uid作为键),并保存与应用程序相关的任何数据.如果您对图片感兴趣,则可能需要经常更新数据.

Usually what I do is load the user data when authentication changes, if it's not there then I save a new object (using the uid as key), with whatever data is relevant for the application. If you're interested in the picture then you might need to update your data often.

您可以在以下问题中找到更深入的解释,包括一些实际示例:

You can find a more in depth explanation, with some actual samples, in the following question: Where does firebase save it's simple login users?.

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

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