با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
از API های دوستان برای تکمیل و تقویت سیستم دوستان موجود در بازی و سایر سیستم های اجتماعی که ممکن است بازی شما به آن دسترسی داشته باشد استفاده کنید. این به شما امکان می دهد بازیکنان را قادر کنید:
دوستان آنها را در بازی خود پیدا کنید.
نمرات را با دوستان خود در تابلوهای امتیازات مقایسه کنید.
فهرست دوستان «بازیهای Play» آنها را با فهرست دوستان موجود درون بازی ترکیب کنید.
بازیکن دیگری را با یک پنجره بازشو نمایه درون بازی شناسایی کنید. این پاپ آپ یک نام مستعار را نشان می دهد که بازیکن فعلی به دوست خود داده است تا آنها بدانند با چه کسی بازی می کنند.
مبانی
این API ها به شما امکان می دهند اقدامات زیر را انجام دهید:
بارگیری دوستان : می توانید بررسی کنید که آیا بازیکن به بازی اجازه داده است به اطلاعات لیست دوستان دسترسی داشته باشد. در صورت اعطای دسترسی، می توانید لیستی از اشیاء Player مربوط به دوستان بازیکن وارد شده را دریافت کنید.
نمایش نمایه بازیهای Play بازیکن دیگری را راهاندازی کنید : میتوانید این نما را باز کنید تا نامی را که بازیکن واردشده به بازیکن دیگر داده است نشان دهید. این نما همچنین کنترل های مدیریت دوستی را ارائه می دهد و بازیکن را از بازی شما خارج نمی کند.
ارائه کنترلهای کاربر : کاربر کنترلهایی برای مدیریت نحوه مشاهده نمایه بازیهای Play برای دوستان و نحوه مشاهده فهرست دوستانش برای بازیها دارد. برای دسترسی به لیست دوستان، کاربر می تواند انتخاب کند که به طور خودکار برای همه بازی ها دسترسی اعطا شود یا می تواند به طور جداگانه برای هر بازی دسترسی را تأیید کند. در نتیجه، هنگام بارگیری لیست دوستان، نتیجه ممکن است یک تماس برای نمایش درخواست دسترسی باشد.
فهرست دوستان بازی های Play را وارد کنید
میتوانید از APIهای دوستان برای دریافت لیستی از دوستان بازیهای Play بازیکنان خود استفاده کنید و آنها را به لیست دوستان درون بازی خود اضافه کنید.
کاربران جدید یک لیست شروع از دوستان برای بازی خواهند داشت، و کاربران فعلی میتوانند دوستان بازیهای Play خود را به هر فهرستی از دوستان داخل بازی وارد کنند. در نتیجه، کاربران شما بزرگترین مجموعه ممکن از بازیکنان را برای بازی یا رقابت با آنها خواهند داشت.
دوستان Play Games را به بازی خود اضافه کنید
با مرتبط کردن شناسه بازیهای Play آنها با اطلاعات بازیکن مربوطه در پایگاه داده داخلی خود، دوستان بازیهای Play را به فهرست دوستان موجود در بازی اضافه کنید. مطمئن شوید که دکمهای با نماد بازیهای Play در کنار این دوستان دارید که با فشردن آن، نمایه بازیکن دیگر را نشان میدهد تا کاربران شما بتوانند بدانند دوستان چه کسانی هستند.
هنگام استفاده از لیست دوستان از یک سرور باطن، به جای ارسال نتیجه API Android، آن را با استفاده از REST API به طور ایمن بارگیری کنید . مطمئن شوید که از شناسه بازیکنی که توسط players.get(me) بازگردانده شده است در REST API برای بازیکنی که در حال حاضر وارد سیستم شده است استفاده کنید، زیرا این شناسه با شناسه مشاهده شده توسط بازیکنان دیگر مطابقت دارد.
اگر لیست دوستان افزوده شده ذخیره نمی شود (اما فقط در زمان مشاهده استفاده می شود)، پس نیازی به کار اضافی نیست.
به بازیهای Play دسترسی بدهید
اگر بازی شما از قبل به بازیهای Play دسترسی ندارد، زمان خوبی برای درخواست رضایت کاربران زمانی است که لیست دوستان درون بازی شما را مشاهده میکنند. برای مثال، میتوانید دکمهای به نام وارد کردن دوستان بازیهای Play اضافه کنید، که در صورت ضربه زدن از کاربر درخواست رضایت میکند. (حتما از نشانواره «بازیهای Play» روی هر دکمهای که به خدمات اشاره میکند استفاده کنید.)
نمایه بازیکن دیگر را مشاهده کنید
میتوانید به بازیکنی که به سیستم وارد شده اجازه دهید نمایه بازیهای Play بازیکن دیگری را مشاهده کند. این به بازیکنی که وارد سیستم شده است اجازه میدهد نامی را که به بازیکن دیگر دادهاند و اینکه آیا قبلاً دوست هستند یا خیر، ببیند، و به آنها زمینه بیشتری در مورد رابطه میدهد. اگر بازیکنان هنوز دوست نیستند، بازیکنی که وارد سیستم شده است، کنترلهای مدیریت دوستی را در نمای نمایه مشاهده میکند. هنگامی که دوستی از داخل بازی ایجاد می شود، نام های پیش فرض برای دو بازیکن، نام های درون بازی آنها است (در صورت ارائه). نام بازی که در آن دوستی آغاز شد نیز نشان داده شده است.
تابلوهای امتیازات اجتماعی
از API های دوستان می توان برای تابلوهای امتیازات نیز استفاده کرد. از این ویژگی برای نشان دادن رتبه بازیکن فعلی در میان دوستان Play Games خود استفاده کنید. توجه داشته باشید که این فقط برای کاربرانی اعمال میشود که انتخاب کردهاند این اطلاعات را با برنامه شما به اشتراک بگذارند و اگر کاربران در بازیهای Play دوستان هستند. برای پشتیبانی از این ویژگی، بازی کنترلی را در اختیار کاربر قرار می دهد. این کنترل از آرگومان collection برای انتخاب نمای اجتماعی تابلوی امتیازات استفاده می کند. برای کسب اطلاعات بیشتر، به بخش تابلوهای امتیازات عمومی و اجتماعی مراجعه کنید.
اگر مجموعه تابلوهای امتیازات اجتماعی را پیادهسازی کنید، فراخوانی برای بارگیری امتیازهای تابلوی امتیازات ممکن است یک استثنای رزولوشن مورد نیاز رضایت مشابه با loadFriends() را برگرداند. اگر رابط کاربری پیشفرض ارائهشده توسط «بازیهای Play» را پیادهسازی کنید (مثلاً getLeaderboardIntent() )، این بهطور خودکار برای شما انجام میشود.
مراحل بعدی
قبل از شروع به استفاده از API های دوستان، موارد زیر را انجام دهید:
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],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)."]]