With instant games, there are many ways to enable social interaction between players.
The FBInstant.player.getConnectedPlayersAsync()
method retrieves a list of users that are connected to the current player through Messenger. This method will return only connected users that have granted permission for the game to access their information.
Note: The method will not differentiate between players who have or have not been playing in the same context. You can fetch information specific to that context from FBInstant.context.getPlayersAsync()
.
Fetch Player's Friends FBInstant.player.getConnectedPlayersAsync() .then(function(players) { _leaderboard.render(players); }); Fetch Context Players FBInstant.context.getPlayersAsync() .then(function(players) { _leaderboard.render(players); }); |
Instant Games can be played in many different contexts, such as Messenger conversations or Feed stories. With the SDK calls below, you can switch contexts from any session, regardless of its entry point. This means you can allow your players to switch to other conversations without requiring them to quit and re-open the game.
We offer three different context change methods:
FBInstant.context.chooseAsync()
opens a native dialog that allows the player to select which conversation they want to change to.FBInstant.context.switchAsync(contextId)
allows the developer to send the player to a pre-defined context (for instance, to continue a match that has previously started in a different conversation).FBInstant.context.createAsync(playerId)
attempts to create a context with the specified player (for example, to start a match between a player and a suggested friend).We provide tools for your game to bring players into new contexts with our context and matchmaking APIs. We've found that people who play with other players end up retaining better than solo context players. There's a couple reasons for this:
Meaningful social dynamics in the gameplay itself will make your instant game shine, and excite players enough to share your game with all their friends.
Recommended usage:
By calling matchPlayerAsync()
, your game will attempt to match the current player into a context with another player. We have added an additional parameter to specify whether you want the game to switch into the newly created context right after the player is matched, or wait until the player has clicked Play in the toast.
There are two matching mechanisms:
The default minimum and maximum number of players in one matched thread are 2 and 20 respectively, depending on how many players are trying to get matched around the same time. The values can be changed in fbapp-config.json.