簡體   English   中英

如何在python中獲取firebase當前用戶ID(uid)?

[英]How do I get the firebase current user id (uid) in python?

我需要獲取當前的用戶 ID。
在 Javascript 中,我使用它來獲取 id

uid = firebase.auth().currentUser.uid // uid= ABO0Xc2E6KSDodEhenICkXF371x1 

我如何在python中獲取uid?

你沒有提到圖書館,但你所有的其他問題都在使用 Pyrebase,所以瀏覽一下文檔(你絕對應該閱讀)......

# Get a reference to the auth service
auth = firebase.auth()

# Log the user in
user = auth.sign_in_with_email_and_password(email, password)

# Get the user's idToken 
token = user['idToken']

用戶 = auth.sign_in_with_email_and_password(email,password) 打印(用戶 ['localId'])

這將在輸出屏幕上顯示當前的 Firebase UID

這是無需登錄或注冊即可檢索用戶 ID 的代碼。

auth.current_user['localId']

重新提出一個老問題,但查看此處的 Pyrebase 文檔,我注意到當您刷新令牌時,用戶 ID(與其他身份驗證函數相比)被檢索。 所以我的解決方案是:

user = auth.sign_in_with_email_and_password("email", "pass")
user = auth.refresh(user['refreshToken'])    
print(user['userId'])

編輯:

我現在甚至在刷新之前看到用戶對象中有一個“localId”變量 - 正如@Abdul 所指出的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM