โหลดเพื่อน: คุณสามารถตรวจสอบได้ว่าผู้เล่นอนุญาตให้เกมเข้าถึงข้อมูลรายชื่อเพื่อนหรือไม่ หากได้รับสิทธิ์เข้าถึง คุณจะได้รับรายการออบเจ็กต์ Player ที่สอดคล้องกับเพื่อนของผู้เล่นที่ลงชื่อเข้าใช้
เปิดมุมมองโปรไฟล์ Play Games ของผู้เล่นคนอื่น: คุณสามารถเปิดมุมมองนี้เพื่อแสดงชื่อที่ผู้เล่นที่ลงชื่อเข้าใช้ตั้งให้ผู้เล่นคนอื่นๆ ได้ มุมมองนี้ยังมีการควบคุมการจัดการมิตรภาพและจะไม่นำผู้เล่นออกจากเกม
ให้การควบคุมแก่ผู้ใช้: ผู้ใช้มีการควบคุมเพื่อจัดการระดับการเข้าถึงโปรไฟล์ Play Games ของเพื่อนและระดับการเข้าถึงรายชื่อเพื่อนของเกม สําหรับสิทธิ์เข้าถึงรายชื่อเพื่อน ผู้ใช้สามารถเลือกที่จะให้สิทธิ์เข้าถึงโดยอัตโนมัติสําหรับทุกเกม หรือเลือกอนุมัติสิทธิ์เข้าถึงทีละเกมก็ได้ ดังนั้น เมื่อโหลดรายชื่อเพื่อน ผลลัพธ์อาจเป็นการเรียกกลับเพื่อแสดงคำขอเข้าถึง
นำเข้ารายชื่อเพื่อนใน Play Games
คุณสามารถใช้ Friends API เพื่อดูรายชื่อเพื่อนใน Play Games ของผู้เล่นและเพิ่มลงในรายชื่อเพื่อนในเกมได้
ผู้ใช้ใหม่จะมีรายชื่อเพื่อนเริ่มต้นไว้เล่นด้วย ส่วนผู้ใช้เดิมจะนำเข้าเพื่อนใน Play Games ไปยังรายชื่อเพื่อนในเกมได้
ด้วยเหตุนี้ ผู้ใช้จึงมีผู้เล่นจำนวนมากที่สุดที่จะเล่นด้วยหรือแข่งขันด้วย
เพิ่มเพื่อนใน Play Games ไปยังเกมของคุณ
เพิ่มเพื่อนใน Play Games ลงในรายชื่อเพื่อนในเกมที่มีอยู่โดยเชื่อมโยงรหัส Play Games ของเพื่อนกับข้อมูลผู้เล่นที่เกี่ยวข้องในฐานข้อมูลภายใน ตรวจสอบว่าคุณมีปุ่มที่มีไอคอน Play Games ข้างๆ เพื่อนเหล่านี้ ซึ่งจะแสดงโปรไฟล์ของผู้เล่นคนอื่นๆ เมื่อกด เพื่อให้ผู้ใช้ทราบว่าเพื่อนคือใคร
เมื่อใช้รายชื่อเพื่อนจากเซิร์ฟเวอร์แบ็กเอนด์ ให้โหลดอย่างปลอดภัยโดยใช้ REST API แทนการส่งผลลัพธ์ของ Android API อย่าลืมใช้รหัสผู้เล่นที่ players.get(me) แสดงใน REST API สำหรับผู้เล่นที่ลงชื่อเข้าใช้อยู่ในขณะนี้ เนื่องจากรหัสนี้จะสอดคล้องกับรหัสที่ผู้เล่นคนอื่นๆ เห็น
หากเกมของคุณยังไม่มีสิทธิ์เข้าถึง Play Games ช่วงเวลาที่เหมาะสมในการแจ้งให้ผู้ใช้ให้ความยินยอมคือเมื่อผู้ใช้ดูรายชื่อเพื่อนในเกม เช่น คุณอาจเพิ่มปุ่มชื่อนำเข้าเพื่อนใน Play Games ซึ่งจะแสดงข้อความขอความยินยอมจากผู้ใช้เมื่อแตะ (อย่าลืมใช้โลโก้ Play Games ในปุ่มที่พูดถึงบริการ)
ดูโปรไฟล์ของผู้เล่นคนอื่น
คุณสามารถอนุญาตให้ผู้เล่นที่ลงชื่อเข้าใช้ดูโปรไฟล์ Play Games ของผู้เล่นคนอื่นๆ ได้ ซึ่งจะช่วยให้ผู้เล่นที่ลงชื่อเข้าใช้เห็นชื่อที่ตนตั้งให้ผู้เล่นคนอื่นๆ และเห็นว่าเป็นมิตรกันอยู่แล้วหรือไม่ ซึ่งจะเป็นบริบทเพิ่มเติมเกี่ยวกับความสัมพันธ์ หากผู้เล่นยังไม่ได้เป็นเพื่อนกัน ผู้เล่นที่ลงชื่อเข้าใช้จะเห็นการควบคุมการจัดการมิตรภาพในมุมมองโปรไฟล์ เมื่อสร้างมิตรภาพจากในเกม ชื่อเริ่มต้นของผู้เล่น 2 คนจะเป็นชื่อในเกม (หากระบุไว้) ระบบจะแสดงชื่อเกมที่เริ่มมิตรภาพด้วย
ลีดเดอร์บอร์ดโซเชียล
นอกจากนี้ คุณยังใช้ Friends API สำหรับตารางอันดับได้ด้วย ใช้ฟีเจอร์นี้เพื่อแสดงอันดับของผู้เล่นปัจจุบันในหมู่เพื่อนใน Play Games โปรดทราบว่าการดำเนินการนี้มีผลกับผู้ใช้ที่เลือกแชร์ข้อมูลนี้กับแอปพลิเคชันของคุณเท่านั้น และในกรณีที่ผู้ใช้เป็นเพื่อนกันใน Play Games เกมจะแสดงการควบคุมให้ผู้ใช้เห็นเพื่อรองรับฟีเจอร์นี้ การควบคุมนี้ใช้อาร์กิวเมนต์ collection เพื่อเลือกมุมมองโซเชียลของลีดเดอร์บอร์ด ดูข้อมูลเพิ่มเติมได้ที่ส่วนตารางอันดับแบบสาธารณะและแบบโซเชียล
หากคุณใช้คอลเล็กชันลีดเดอร์บอร์ดโซเชียล การเรียกให้โหลดคะแนนลีดเดอร์บอร์ดอาจแสดงข้อยกเว้นการแก้ปัญหาที่ต้องได้รับความยินยอมซึ่งคล้ายกับจาก loadFriends()
หากคุณใช้ UI เริ่มต้นที่ Play Games มีให้ (เช่น getLeaderboardIntent()) ระบบจะจัดการเรื่องนี้ให้คุณโดยอัตโนมัติ
[[["เข้าใจง่าย","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-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)."]]