有効な Google アカウントに対応していないメールアドレスを使用して User コンストラクタが呼び出された場合、オブジェクトは作成されても実際の Google アカウントには対応しません。こうしたケースは、オブジェクトが保存された後に、特定のメールアドレスを使用して Google アカウントを作成する場合にも起こります。User 値の作成時に Google アカウントを表していないメールアドレスがその値に含まれていると、その User 値は実際のユーザーを表す User 値とは一致しません。
開発用ウェブサーバーで実行されている場合、すべての User オブジェクトは(シミュレートされた)データストアへの保存時には、有効な Google アカウントを表すと想定されます。
有効なユーザーの User オブジェクトにより、そのユーザーの一意の ID 値が得られます。この値はそのユーザーがメールアドレスを変更しても変わりません。この ID(str 値)は user_id() メソッドによって返されます。
User オブジェクトは、アプリでどの認証方式を使用する場合でも同じ形式になります。
データストアでユーザー値を使用する
ユーザー ID は不変であるため、キー名の中や文字列プロパティとして使用できます。そのため、ユーザー値を使用するときは、ユーザー ID(場合によってはユーザーとのメール通信で最後に確認したメールアドレス)を保存します。次の例は、現在のユーザーとユーザー ID を比較する方法を示しています。
UserProperty にはメールアドレスとユーザーの一意の ID が含まれているため、これを保存しないことを強くおすすめします。ユーザーがメールアドレスを変更すると、そのユーザーの古いメールアドレス(User に格納されている)と新しい User の値を比較したときに一致しません。代わりに、User のユーザー 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-03-13 UTC。"],[[["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."]]],[]]