Use Friends APIs to complement and enhance your existing in-game friends system and other social systems your game may access. This lets you enable players to:
Find their friends in your game.
Compare scores with their friends on leaderboards.
Combine the list of their Play Games friends with existing in-game lists of friends.
Identify another player with an in-game profile popup. This popup shows a nickname that the current player has given to their friend, so they know who they’re playing with.
Basics
These APIs allow you to perform the following actions:
- 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.
- 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.
- 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.
Import a Play Games friends list
You can use the Friends APIs to get a list of your players’ Play Games friends and add them to your in-game friends list.
New users will have a starting list of friends to play with, and existing users can import their Play Games friends into any in-game lists of friends. As a result, your users will have the largest possible set of players to play with or compete against.
Add Play Games friends to your game
Add Play Games friends to any existing in-game friends list by associating their Play Games ID with corresponding player information in your internal database. Make sure you have a button with the Play Games icon next to these friends, which shows the other player's profile when pressed, so your users can know who the friends are.
When using the friends list from a backend server, load it securely
using the REST API rather than passing the result of the Android API. Make sure
to use the player ID returned by players.get(me)
in the REST API for the
currently signed-in player, as this will be consistent with the ID seen by other
players.
If the augmented friends list is not stored (but just used at the time of viewing), then no additional work is needed.
Grant Play Games access
If your game doesn’t already have Play Games access, a good time to prompt users for their consent is when they view your in-game friends list. For example, you might add a button called Import Play Games friends, which prompts the user for consent when tapped. (Make sure to use the Play Games logo on any button that mentions the service.
View another player's profile
You can allow your signed-in player to view another player's Play Games profile. This allows the signed-in player to see the name they have given the other player and whether or not they are already friends, giving them added context about the relationship. If the players are not yet friends, the signed-in player will see friendship management controls on the profile view. When friendships are created from within the game, the default names for the two players are their in-game names (if you provide one). The name of the game where the friendship was initiated is also shown.
Social leaderboards
The Friends APIs can also be used for leaderboards. Use this feature to show the
ranking of the current player among their Play Games friends. Note that
this only applies to users who have chosen to share this information with your
application, and if the users are friends in Play Games. To support this
feature, the game exposes a control to the user. This control uses the
collection
argument to select the social view of the leaderboard. To learn
more, see the section on
public and social leaderboards.
If you implement the social leaderboards collection, the call to load the
leaderboard scores may return a consent-required resolution exception similar to
that from
loadFriends()
.
If you implement the default Play Games-provided UI (for example,
getLeaderboardIntent()
),
then this is handled for you automatically.
Next steps
Before you start to use the Friends APIs, do the following:
- Download and review a code sample:
- Java
- Unity sample app using the Unity plugin
- Familiarize yourself with the recommendations described in the Quality Checklist.
- Implement the Friends APIs in a Java client.