-
Notifications
You must be signed in to change notification settings - Fork 9
Connected Players
Mat Hopwood edited this page Nov 8, 2018
·
8 revisions
Connected players are users that play the game and are friends with the user. Leaderboards can also be scoped by connected players enabling friends to compete directly against each other for the top spots.
You can get a list of the users connected players as follows:
FBInstant.player.getConnectedPlayersAsync()
.then(function(players) {
// players is a collection of UserService.Player objects
});
You can add another user as a friend if you have their gamer ID:
if (FBInstant.ext !== undefined)
{
FBInstant.ext.addFriendAsync(gamer_id).then(function(success) {
if (success)
// Friend added
});
}
Passing gamer ID's around can be done a variety of ways, you can:
- Share a link which contains the users game id. When the recipient clicks the link they can add the sender as a friend
- Display the users game ID to them and ask them to copy and send it to their friend. The recipient can then add their friend using the ID that was sent
- User search - coming soon
Users can also remove a friend from their connected players list:
if (FBInstant.ext !== undefined)
{
FBInstant.ext.removeFriendAsync(gamer_id).then(function(success) {
if (success)
// Friend removed
});
}
You can search for users by user name and email as follows:
if (FBInstant.ext !== undefined)
{
FBInstant.ext.listUsersAsync("myfriend", 0, 10, function(users) {
// users contains a list of all users that match
})
}
Note that only some service providers provide access to user management, you should check if functionality is available by querying supported API's, e.g.:
if (FBInstant.getSupportedAPIs().includes("ext.listUsersAsync"))
{
// Safe to use
}
