友だちを読み込む: プレーヤーが友だちリスト情報へのアクセスをゲームに許可しているかどうかを確認できます。アクセスが許可されている場合、ログインしているプレーヤーの友だちに対応する Player オブジェクトのリストを取得できます。
別のプレーヤーの Play ゲーム プロフィールのビューを起動する: このビューを開くと、ログインしているプレーヤーが相手プレーヤーに付けた名前が表示されます。このビューでは友だち関係を管理することもでき、プレーヤーがゲームから出ることはありません。
ユーザー コントロールを提供する: Play ゲーム プロフィールを友だちに公開する方法や、友だちリストをゲームに公開する方法を管理するためのコントロールが用意されています。友だちリストに対するアクセスについて、ユーザーはすべてのゲームに対し自動的にアクセス権を付与するか、ゲームごとに個別にアクセスを承認するかを選択できます。そのため、友だちリストを読み込むと、その結果はアクセスのリクエストを表示するコールバックになる場合があります。
Play ゲームの友だちリストをインポートする
Friends API を使用することで、プレーヤーの Play ゲームの友だちリストを取得し、ゲーム内の友だちリストに追加できます。
Play ゲームの友だちをゲーム内の既存の友だちリストに追加するには、Play ゲーム ID を、内部データベースにある対応するプレーヤー情報と関連付けます。こうした友だちの横に Play ゲームのアイコンのボタンがあります。このボタンを押すと相手プレーヤーのプロフィールが表示されるため、ユーザーはその友だちが誰なのかを把握できます。
バックエンド サーバーから友だちリストを使用する場合、Android API の結果を渡すのではなく、REST API を使用して安全に読み込んでください。現在ログインしているプレーヤーについて、REST API で players.get(me) が返すプレーヤー ID を使用するようにします。これにより、他のプレーヤーに表示される ID との整合性が確保されます。
拡張した友だちリストを保存しない(表示中にのみ使用する)場合、追加の作業は必要ありません。
Play ゲームのアクセス権を付与する
ゲームに Play ゲームへのアクセス権がまだ付与されていない場合は、ゲーム内の友だちリストを表示するとき、同意を求めるプロンプトをユーザーに表示することをおすすめします。たとえば「Play ゲームの友だちをインポート」というボタンを追加し、タップすると同意を求めるプロンプトがユーザーに表示されるようにします(サービスに言及するボタンには、必ず Play ゲームのロゴを使用してください)。
別のプレーヤーのプロフィールを表示する
ログインしているプレーヤーに対して、別のプレーヤーの Play ゲーム プロフィールを表示することを許可できます。これにより、ログインしているプレーヤーは、相手プレーヤーに付けた名前と、すでに友だちになっているかどうかを確認でき、友だち関係についての補足情報を得られます。相手プレーヤーとまだ友だちになっていない場合、友だち関係を管理するコントロールがプロフィール ビューに表示されます。ゲーム内から友だち関係を作成した場合、2 人のプレーヤーのデフォルト名はゲーム内の名前です(存在する場合)。友だち関係が開始したゲームの名前も表示されます。
ソーシャル リーダーボード
Friends API はリーダーボードにも使用できます。この機能を使用して、Play ゲームの友だち間における現在のプレーヤーのランキングを表示します。これは、この情報をアプリと共有することにしたユーザーが Play ゲームで友だちになっている場合に、そのユーザーに対してのみ適用されます。この機能をサポートするために、ゲームはユーザーにコントロールを公開します。このコントロールは collection 引数を使用して、リーダーボードのソーシャル ビューを選択します。詳細については、公開リーダーボードとソーシャル リーダーボードのセクションをご覧ください。
[null,null,["最終更新日 2025-07-26 UTC。"],[],[],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)."]]