我在 GAE 標準 node.js 環境中有一個站點儀表板,它在我的檔案中的元素中使用login: admin選項。此選項使 google 登錄視窗在訪問站點之前出現。是否可以獲得登錄用戶的電子郵件和個人資料?handlers:app.yaml
uj5u.com熱心網友回復:
2月2日更新
在我的本地服務器上測驗
我
login:required在 app.yaml 中添加了;這是一個 Python3 應用程式,但我沒有使用users api;我啟動應用程式dev_appserver.py以確保它app.yaml在開發環境中使用該檔案;當我加載主頁時,它提示我登錄[email protected]我轉儲了標頭輸出,它包括以下內容
X-Appengine-User-Email: test@example.com
X-Appengine-User-Id: XXXXX
原始答案
- 您可以使用“用戶”Api 并呼叫該函式
GetCurrentUser()
例如,如果你的代碼是在 python 中,你會有類似的東西
from google.appengine.api import users
# Get information about the currently logged in user
users.GetCurrentUser()
# Extra - if you wanted to confirm this is an admin user
users.IsCurrentUserAdmin()
- 由于您沒有使用 Python,請查看環境變數是否
USER_EMAIL存在。的源代碼有users api下面的片段(所以看看它是否適合你)
email = os.environ.get('USER_EMAIL', email)
_user_id = os.environ.get('USER_ID', _user_id)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/433881.html
