I am trying to get the user ids, signup date and their email addresses from the firebase account to json file using python so that I can just run the command everyday and get the users data updated everyday instead of copy/paste everyday. I have never worked with JSON using python ever before. My boss has provided me 2 links for help which are very useful but I don't know how to write the exact code in Python to get it working. The links he provided me are as follows:
screenshot of the data I require
This might help you: https://firebase.google.com/docs/auth/admin/manage-users#list_all_users
from firebase_admin import auth
# Start listing users from the beginning, 1000 at a time.
page = auth.list_users()
while page:
for user in page.users:
print('User: ' + user.uid)
# Get next batch of users.
page = page.get_next_page()
# Iterate through all users. This will still retrieve users in batches,
# buffering no more than 1000 users in memory at a time.
for user in auth.list_users().iterate_all():
print('User: ' + user.uid)
The above code is from that link. Want you want to do is refactor it and save the users into a dictionary and then export that dictionary as JSON.
from firebase_admin import auth
import json
users = {}
for user in auth.list_users().iterate_all():
users[user.id] = user
with open("output.json", "w") as outfile:
json.dump(users, outfile)
Or some variation of the above that works to your liking, could be a list of users instead.
from firebase_admin import auth
import json
users = []
for user in auth.list_users().iterate_all():
users.append(user)
with open("output.json", "w") as outfile:
json.dump(users, outfile)
``
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.