Firebase / Android - 通过UID加载用户 [英] Firebase/Android - Load User by UID

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

问题描述


$ b

FirebaseUser user = FirebaseAuth.getInstance()。getCurrentUser()获取当前登录用户的代码片段。 ;



但是如果我需要加载另一个用户的数据,比如图像路径和名称呢?我希望通过他们的UID加载他们。



我当然可以像这样保存数据:

   - >用户
- > UID
- > imagePath
- >名称

但是我认为有可能使用 FirebaserUser class。



其实我觉得必须有一些方法,它只是没有写在文档中。 无法直接使用 FirebaseUser 类来完成此操作。旧版文件 Firebase 1.0 (在被Google收购之前)提到了确切的场景和可能的解决方案。目前的文件尚未完成。解决方案是将用户的数据保存在实时数据库中,保持 uid 作为关键字。所以当你需要另一个用户的数据的时候,你只需要记住他们的 UID 并且可以搜索他们的数据(就像你在问题描述中提到的那样)。



当我开始在自己的应用程序上工作时,我搜索了另外一个方法来实现这个功能,但是没有找到其他方法并阅读旧的doc,我放弃了使用数据库的方式。相信我,使用数据库的方式更简单,更灵活,而不是用你的方式来避免使用它。


I have only found code snippets to load the currently logged in user:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

But what if I need to load another user's data, like the image path and name? I want to load them by their UID.

I could of course save the data myself like this:

-> users
    -> UID
        -> imagePath
        -> name

But I thought there might be a way to use the FirebaserUser class.

I actually think there has to be some way, it's just not written in the docs.

解决方案

There's no way to do this directly using FirebaseUser class. The old docs of Firebase 1.0 (Before it was acquired by Google) mentioned that exact scenario and the possible solution. The current doc is not completed yet.

The solution was to save the user's data in the Real-time database keeping the uid as the key. So when you need the data of another user, you'll just have to remember their UID and can search for their data (Exactly like how you mentioned in the question description).

I searched the other way to do that without using Real-time database when I started working on my own app, however after finding no other method and reading the old doc, I gave up and used the database way. Trust me it's way easier and flexible to use the database, instead of hacking your way to avoid using it altogether.

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

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