如果您是使用未對應至有效 Google 帳戶的電子郵件地址來呼叫 User 建構函式,系統會建立物件,但該物件無法對應至確切的 Google 帳戶。即使有人在儲存物件後使用指定的電子郵件地址建立 Google 帳戶,系統仍會顯示相同的訊息。建立 User 值時,如果這個值的電子郵件地址不代表「Google 帳戶」,則該值將永遠無法與代表實際使用者的 User 值配對。
在開發網路伺服器下執行應用程式時,系統會假設所有 User 物件在 (模擬) 資料儲存庫中儲存時,這些物件皆代表有效的 Google 帳戶。
有效使用者的 User 物件可為使用者提供唯一識別碼值,即便使用者變更其電子郵件地址,該值仍會維持不變。user_id() 方法會傳回這個 ID,也就是 str 值。
無論應用程式採用何種驗證方式,User 物件的格式均會相同。
將 User 值與資料儲存庫搭配使用
使用者 ID 是穩定的,您可以在索引鍵名稱中使用,或做為字串屬性使用。因此,使用使用者值時,您應該儲存使用者 ID (以及可能的最後一次看到的電子郵件地址,以便透過電子郵件與使用者聯絡)。以下範例示範如何將目前使用者與使用者 ID 進行比對:
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-06-16 (世界標準時間)。"],[[["The `User` class represents a user and provides unique, comparable instances, where equal instances represent the same user."],["The `users.get_current_user()` function retrieves the `User` instance for the currently authenticated user, regardless of the authentication method."],["`User` instances can be created using an email address or a federated identity, but those created from invalid Google accounts will not match real user accounts."],["The `user_id()` method returns a stable, unique string identifier for a user that persists even if the user changes their email."],["It is recommended to store the `user_id` for user identification in the datastore instead of a `UserProperty` because email addresses may change."]]],[]]