PGS 可以為 Android 玩家提供遊戲身分,但是這不一定是使用者唯一可以使用的身分。您可以同時使用 PGS、社群網路 ID 以及您自己的遊戲內部 ID 系統登入玩家。每種系統都可以為您和玩家提供專用值,並可以同時使用,藉此為 Android 玩家提供良好的使用體驗。
安全擷取並驗證玩家身分,以便進行後端整合
您可以要求伺服器驗證碼,以便在取得登入玩家的授權之後,讓伺服器透過 REST API 直接和 Play 遊戲服務伺服器通訊。這樣做即可直接存取玩家的 ID、個人資料以及其他資訊 (如經過授權的好友名單)。如果您會在後端儲存任何玩家 ID、好友 ID 或其他相關資料,就必須使用此方法,避免裝置端操控這些欄位。
另外如果是某些較舊的遊戲和玩家,則「Android」SDK 回傳的玩家 ID 可能和其他玩家透過該遊戲檢視該名玩家時看到的 ID 不同,尤其是使用好友名單的時候這個情況特別明顯。不過,REST API 內部回傳的 player_id 一定可以保持一致,而且一律會是其他玩家會看到的 ID。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Sign-in\n\nFollowing the deprecation of the\n[Google Sign-In](https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html)\nAPI, we are removing the games v1 SDK in 2026. After February 2025, you will be unable to publish\ntitles that are newly integrated with games v1 SDK, on Google Play. We recommend that you use the\ngames v2 SDK instead. \n\nWhile existing titles with the previous games v1 integrations continue to function for a\ncouple of years, you are encouraged to\n[migrate to v2](/games/pgs/android/migrate-to-v2)\nstarting June 2025. \n\nThis guide is for using the Play Games Services v1 SDK. For information\non the latest SDK version, see the\n[v2 documentation](/games/pgs/signin).\n\nPlay Games Services sign-in provides you with a player's gaming identity, which\nis a platform-level, gaming-specific identity for Android players. This identity\nhelps build a relationship between your game and the player. Players are more\nwilling to use this identity to sign in than with alternate centralized systems.\n\nIn addition, sign-in gives you a strong, consistent identifier that you can use as a key to a\ncloud save system. Cloud save is highly-valued; it enables players to do the\nfollowing:\n\n- Pick up where they left off if they change or reset their device\n- Play the game on multiple devices (for example, on another phone or a Chromebook)\n- Uninstall and later re-install the game\n\nYou can use Play Games Services identity as a key for your own cloud save\nsolution, or you can use the free [Saved Games service](/games/pgs/savedgames).\n\nPlay Games Services (PGS) supports automatic sign-in, a zero-friction way to\nsign in players, as well as manual sign-in, which is a one-click process. This\ndocument describes these different methods of sign-in.\n| **Note:** You can implement sign-in without implementing any other Play Games Services features (for example, leaderboards or saved games). Sign-in is a low-friction way to get a strong identity for your players.\n\nRecommended sign-in flow\n------------------------\n\nIn order to successfully sign players into your game, use the following\nsign-in flow:\n\n1. During the startup sequence of your game, try [Automatic sign-in](#automatic-sign-in) to automatically sign the player in.\n2. If automatic sign-in does not work and the user's device is online, try [Manual sign-in](#manual-sign-in).\n3. If manual sign-in is declined, remember the user's choice and do not show manual sign-in again, but continue to try Automatic sign-in on startup.\n\nAdditionally, you should ensure that users are able to sign into your game with\ntheir Play Games services account with a dedicated, easy-to-find button.\n\nAutomatic sign-in\n-----------------\n\nAutomatic sign-in allows users to sign into your game with zero friction - it's\nautomatic! If your game requests that the user sign in and the automatic sign-in\nsetting is enabled (in the Google Play Games app), then you will receive the\nuser's PGS identity credentials and the user will see the PGS sign-in experience.\n\nAutomatic sign-in is a setting users can control. Users can choose to\nautomatically sign into all games or be asked each time.\n| **Note:** Automatic sign-in only works if the game does not request additional OAuth Scopes. For more information, see [OAuth Scopes and PGS](#oauth-scopes).\n\nManual sign-in\n--------------\n\nIf a user doesn't automatically sign into the game, you can ask them to sign in\nmanually. Users can sign in with one click from a dialogue box displayed on top\nof your game.\n| **Note:** Manual sign-in works better if the game does not request additional OAuth Scopes. For more information, see [OAuth Scopes and PGS](#oauth-scopes).\n\nAllow PGS popups for the correct sign-in experience\n---------------------------------------------------\n\nWhen using PGS, users need to know they are signed in. This is done by showing\nthe PGS sign-in experience.\n\nTo show the sign-in experience, call the\n[`setViewForPopups()`](https://developers.google.com/android/reference/com/google/android/gms/games/GamesClient.html#setViewForPopups(android.view.View))\nmethod of the `GamesClient` class during game startup. This is critical to\nenable the correct user experience.\n\nOAuth Scopes and PGS\n--------------------\n\nPGS relies on the [OAuth\nsystem](https://developers.google.com/identity/protocols/OAuth2) to allow users\nto give your game access to their account.\n[OAuth Scopes](https://developers.google.com/identity/protocols/googlescopes)\nare permissions that you as a developer can request. If granted, these\npermissions let your game call certain APIs on behalf of the user and also give\nyou access to certain parts of their Google Account.\n\nPGS has a unique scope for games (`games-lite`) and relies on another scope\n(`drive.appdata`) if your game uses the saved games feature. The saved games\nfeature gives access to the user's Google Drive account, which is where the game\ndata is stored.\n\nYour game can request any scope that you need to create a great game experience\nfor your users. Your game can request all of the scopes it needs in one bundle,\nlimiting the number of requests for Google Account access. However, this\napproach has a major drawback. If you request more than the PGS-specific scopes,\nautomatic sign-in cannot succeed. Automatic sign-in is the best way to get\nplayers signed into your game.\n\nBest practice is to use incremental scope requests. Your game should ask for\nPGS-only scopes first in the initial request, and request other scopes\nseparately at a more relevant moment.\n\nOAuth access is granted using a different screen for each scope. This allows\nusers to decide, in a granular way, which scopes to give access to. By using\nautomatic sign-in with only PGS scopes, users will not have to interact with any\nOAuth prompts, reducing sign-in friction.\n\nSupport for multiple sign-in methods\n------------------------------------\n\nPGS provides a gaming identity for Android players, but it doesn't need to be\nthe only identity connected to your users. You can sign in players using PGS, a\nsocial network ID, and your own in-game ID system all at the same time. Each\nsystem provides unique value for both you and your players, and all can work\ntogether to make a great experience for Android players.\n\nSecurely retrieve and verify the player identity for backend integration\n------------------------------------------------------------------------\n\nYou can request a Server Auth code to enable your server\nto talk directly to the Play Games Services servers via the REST API with the\nauthority of the signed-in player. This enables direct access to the player's\nID, profile, and other information (such as friends list, if authorized). If you\nstore any Player IDs, friend IDs, or other related data in your backend, this\nmethod must be used to remove the potential for\ndevice-side manipulation of these fields.\n\nAdditionally, for some older games and players, the player ID returned by the\n*Android* SDK for a player may not be the same ID that other players see when\nviewing that player in the same game - this is particularly relevant when using\nthe friends list. However, the `player_id` returned within the REST API is\nalways consistent and is always the ID that is seen by other players.\n\nFor more information, see\n[Offline access](/games/pgs/v1/android/server-access) and the\n[REST API](/games/services/web/api/rest) documentation.\n\nClient implementation\n---------------------\n\nTo learn how to implement sign-in support on Android, see\n[Sign-in in Android Games](/games/pgs/v1/android/signin)."]]