[英]List all users from Firebase Authentication
I am currently using the Pyrebase wrapper to get information (such as their email and created date) of all users.我目前正在使用 Pyrebase 包装器来获取所有用户的信息(例如他们的 email 和创建日期)。 I tried looking through the documentation and cross reference it to Pyrebase documentation however i don't seem to get what i'm looking for.
我尝试查看文档并将其交叉引用到 Pyrebase 文档,但我似乎没有得到我正在寻找的东西。 Currently i have tried this:
目前我已经尝试过这个:
import pyrebase
config={all required information, including path to service account .json file}
firebase=pyrebase.initialize_app(config)
db=firebase.database()
auth=firebase.auth()
extract_user = db.child('users').child('userId').get()
for x in extract_user.each():
print(x.val())
auth.get_account_info(user[x.val()])
However i still failed, i know im missing something but im not sure what.但是我仍然失败了,我知道我错过了一些东西但我不确定是什么。
Note: I saved the users userID in the database under userId.注意:我将用户userID保存在数据库中的userId下。 So i looped through each and every ID to be used in the 'get_account_info'
所以我遍历了要在“get_account_info”中使用的每个 ID
Any suggestions or ways i can get this to be done?有什么建议或方法可以完成吗?
from firebase_admin import credentials
from firebase_admin import auth
cred = credentials.Certificate("./key.json")
initialize_app(cred, {'databaseURL' : "your database..."})
page = auth.list_users()
while page:
for user in page.users:
print("user: ", user.uid)
page = page.get_next_page()
Then, after you get user id that looks like "F5aQ0kAe41eV2beoasfhaksfjh2323alskjal" you can see the actual email by:然后,在您获得类似于“F5aQ0kAe41eV2beoasfhaksfjh2323alskjal”的用户 ID 后,您可以通过以下方式查看实际的 email:
user = auth.get_user("F5aQ0kAe41eV2beoasfhaksfjh2323alskjal")
print("user email: ", user.email)
The db.child('users').child('userId').get()
in your code reads users from the Realtime Database, where they'll only exist if your application added the there explicitly.您代码中的
db.child('users').child('userId').get()
从实时数据库中读取用户,只有当您的应用程序显式添加该用户时,它们才会存在。 Adding a user to Firebase Authentication does not automatically also add it to the Realtime Database.将用户添加到 Firebase 身份验证不会自动将其添加到实时数据库。
While Pyrebase allows you to initialize it with a service account, it doesn't replicate all administrative functionality of the Firebase Admin SDKs.虽然 Pyrebase 允许您使用服务帐户对其进行初始化,但它不会复制 Firebase Admin SDK 的所有管理功能。 As far as I can see in Pyrebase's code , Pyrebase's does not implement a way to list users.
据我在Pyrebase 的代码中看到的,Pyrebase 没有实现列出用户的方法。
Consider using the Firebase Admin SDK, which has a built-in API to list users .考虑使用 Firebase Admin SDK,它有一个内置的API 来列出用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.