列出来自 Firebase 身份验证的所有用户

List all users from Firebase Authentication

我目前正在使用 Pyrebase 包装器来获取所有用户的信息(例如他们的电子邮件和创建日期)。我尝试查看文档并将其交叉引用到 Pyrebase 文档,但我似乎没有得到我正在寻找的东西。目前我已经尝试过这个:

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()])

但是我还是失败了,我知道我错过了一些东西,但我不确定是什么。

注意:我把用户的userID保存在数据库的userId下。所以我遍历了要在 'get_account_info'

中使用的每个 ID

有什么建议或方法可以完成吗?

您代码中的 db.child('users').child('userId').get() 从实时数据库中读取用户,只有当您的应用程序明确将其添加到实时数据库中时,他们才会存在。将用户添加到 Firebase 身份验证不会自动将其也添加到实时数据库。

虽然 Pyrebase 允许您使用服务帐户对其进行初始化,但它不会复制 Firebase Admin SDK 的所有管理功能。据我在 Pyrebase's code 中看到的,Pyrebase 没有实现列出用户的方法。

考虑使用 Firebase Admin SDK,它内置了 API to list users

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:


user = auth.get_user("F5aQ0kAe41eV2beoasfhaksfjh2323alskjal")
print("user email: ", user.email)