啟動其他玩家的 Play 遊戲個人資料檢視畫面:您可以開啟此檢視畫面,顯示已登入玩家提供的其他玩家名稱。此檢視畫面也提供好友管理控制選項,而且不會導致玩家離開遊戲。
提供使用者控制選項:使用者可以利用控制選項管理自己像好友顯示的 Play 遊戲個人資料,以及自己在遊戲中顯示的好友名單。對於好友名單存取權而言,使用者可以選擇自動授予所有遊戲的存取權,或者也可以選擇個別核准每個遊戲的存取權。因此載入好友清單時,結果可能是回呼,用於顯示存取權要求。
匯入 Play 遊戲好友名單
您可以使用 Friends API 取得玩家的 Play 遊戲好友名單,並將這些玩家加入遊戲中的好友名單。
新使用者將取得一份開始玩遊戲的好友名單,現有使用者也可以將自己的 Play 遊戲好友匯入任何遊戲內的好友名單。因此,您的使用者將擁有最大的玩家組合,可以和這些玩家一起玩遊戲或比賽。
在遊戲中加入 Play 遊戲好友
在內部資料庫中建立 Play 遊戲 ID 與對應玩家資訊之間的關係,就可將 Play 遊戲好友加入至任何現有的遊戲內好友清單。請確認這些好友旁有 Play 遊戲圖示的按鈕,按下這些按鈕就可顯示其他玩家的個人資料,這樣使用者就可以知道這些好友是誰。
從後端伺服器使用好友名單時,請使用 REST API 安全載入,而不傳遞 Android API 的結果。目前登入的玩家必須在 REST API 中使用 players.get(me) 傳回的玩家 ID,因為這個 ID 會與其他玩家可以查看 ID 相同。
如果沒有儲存擴增好友名單 (而只是在檢視時使用),那麼就不需要進行額外的操作。
授予 Play 遊戲存取權
如果您的遊戲沒有 Play 遊戲存取權,建議在使用者檢視遊戲內的好友名單時,通知他們並徵求同意。舉例來說,您可以加入一個名稱為「匯入 Play 遊戲好友」的按鈕,這可在使用者輕觸按鈕時提示使用者同意。(請務必在提及服務的任何按鈕上使用 Play 遊戲標誌)。
檢視其他玩家的個人資料
您可以允許已登入的玩家查看其他玩家的 Play 遊戲個人資料。這可讓已登入的玩家查看他們向其他玩家顯示的名稱,以及他們是否已經為好友,並允許他們加入關係相關的背景資訊。如果玩家還不是好友,則登入的玩家可以在個人資料檢視畫面中查看好友關係管理控制選項。在遊戲中建立好友關係後,這兩名玩家的預設名稱即為他們在遊戲內的名稱 (如果有的話)。系統也會顯示建立好友關係的遊戲名稱。
社群排行榜
Friends API 也可用於排行榜。使用此功能可以顯示目前玩家在 Play 遊戲好友中的排名。請注意,這項功能僅適用於選擇與應用程式分享這些資訊的使用者,以及使用者是 Play 遊戲中好友的情況。為了支援此功能,遊戲會向使用者顯示控制選項。此控制選項會使用 collection 引數選取排行榜的社交檢視畫面。詳情請參閱「公開和社交排行榜」一節。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Friends\n\nUse the Friends APIs to complement and enhance your existing in-game friends system\nand other social systems your game may access. This lets you enable players to:\n\n- Find their friends in your game.\n\n- Compare scores with their friends on leaderboards.\n\n- Combine the list of their Play Games friends with existing in-game lists of\n friends.\n\n- Identify another player with an in-game profile popup. This popup shows a\n nickname that the current player has given to their friend, so they know who\n they are playing with.\n\nBasics\n------\n\nThese APIs allow you to perform the following actions:\n\n- **Load friends**: You can check if the player has allowed the game to access Friends list information. If access is granted, you can get a list of Player objects corresponding to the friends of the signed-in player.\n- **Launch a view of another player's Play Games profile**: You can open up this view to show the name given to the other player by the signed-in player. This view also offers friendship management controls and won't take the player out of your game.\n- **Provide user controls**: The user has controls to manage how their Play Games profile is visible to friends and how their friends list is visible to games. For friends list access, the user can choose to automatically grant access for all games or they can choose to individually approve access for each game. Consequently, when loading the friends list, the result may be a callback to display a request for access.\n\nImport a Play Games friends list\n--------------------------------\n\nYou can use the Friends APIs to get a list of your players' Play Games\nfriends and add them to your in-game friends list.\n\nNew users will have a starting list of friends to play with, and existing users\ncan import their Play Games friends into any in-game lists of friends.\nAs a result, your users will have the largest possible set of players to play\nwith or compete against.\n| **Note:** If you store any relationships from Play Games, you must regularly check the friends list to ensure that the relationships, and consent to use them, are still valid.\n\n### Add Play Games friends to your game\n\nAdd Play Games friends to any existing in-game friends list by\nassociating their Play Games ID with corresponding player information in\nyour internal database. Make sure you have a button with the Play Games\nicon next to these friends, which shows the other player's profile when pressed,\nso your users can know who the friends are.\n\nWhen using the friends list from a backend server,\n[load it securely](/games/pgs/signin#secure-access)\nusing the REST API rather than passing the result of the Android API. Make sure\nto use the player ID returned by\n[`players.get(me)`](/games/services/web/api/rest/v1/players/get)\nin the REST API for the currently signed-in player, as this will be consistent\nwith the ID seen by other players.\n\nIf the augmented friends list is not stored (but just used at the time of\nviewing), then no additional work is needed.\n\n### Grant Play Games access\n\nIf your game doesn't already have Play Games access, a good time to\nprompt users for their consent is when they view your in-game friends list. For\nexample, you might add a button called **Import Play Games friends**, which\nprompts the user for consent when tapped. (Make sure to use the\nPlay Games logo on any button that mentions the service.)\n\nView another player's profile\n-----------------------------\n\nYou can allow your signed-in player to view another player's\nPlay Games profile. This allows the signed-in player to see the name they\nhave given the other player and whether or not they are already friends, giving\nthem added context about the relationship. If the players are not yet friends,\nthe signed-in player will see friendship management controls on the profile\nview. When friendships are created from within the game, the default names for\nthe two players are their in-game names (if provided). The name of the\ngame where the friendship was initiated is also shown.\n\nSocial leaderboards\n-------------------\n\nThe Friends APIs can also be used for leaderboards. Use this feature to show the\nranking of the current player among their Play Games friends. Note that\nthis only applies to users who have chosen to share this information with your\napplication, and if the users are friends in Play Games. To support this\nfeature, the game exposes a control to the user. This control uses the\n`collection` argument to select the social view of the leaderboard. To learn\nmore, see the section on\n[public and social leaderboards](/games/pgs/leaderboards#public_and_social_leaderboards).\n\nIf you implement the social leaderboards collection, the call to load the\nleaderboard scores may return a consent-required resolution exception similar to\nthat from\n[`loadFriends()`](https://developers.google.com/android/reference/com/google/android/gms/games/PlayersClient#loadFriends(int,%20boolean)).\nIf you implement the default Play Games-provided UI (for example,\n[`getLeaderboardIntent()`](https://developers.google.com/android/reference/com/google/android/gms/games/LeaderboardsClient.html#getLeaderboardIntent(java.lang.String))),\nthen this is handled for you automatically.\n\nNext steps\n----------\n\nBefore you start to use the Friends APIs, do the following:\n\n- Download and review a code sample:\n - [Java](https://github.com/playgameservices/android-basic-samples)\n - [Unity sample app](https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/Samples/SmokeTest) using the [Unity plugin](https://github.com/playgameservices/play-games-plugin-for-unity)\n- Familiarize yourself with the recommendations described in the [Quality Checklist](/games/pgs/quality#friends).\n- Implement the [Friends APIs in a Java client](/games/pgs/android/friends)."]]