Social Features: Rendering Player Data

Rendering an arbitrary player

You can render the data of any player in an overlay view as long as you have the player ID.

<View>
  <Image src="{{FBInstant.players[{{playerID}}].photo}}" />
  <Text content="{{FBInstant.players[{{playerID}}].name}}" />
</View>

Notes:

  • The player you want to render does not have to be connected to or be in the same context as the current player.
  • If a player chooses to use their real profile picture in your game (as opposed to a gaming avatar image), the resulting image will be of size 128x128 pixels.

Use cases

You can use this functionality to build your own custom leaderboard or matchmaking feature. For example, if you have a list of player IDs for your custom leaderboard, you can then render the players in the leaderboard by iterating through the list like so:

<View>
    <For source="{{players}}" itemName="i">
        <View onTapEvent="SendGift_{{i.playerID}}">
            <Image src="{{FBInstant.players[{{i.playerID}}].photo}}" />
            <Text content="{{FBInstant.players[{{i.playerID}}].name}}" />
        </View>
    </For>
</View>
{
    "players": 
    [
        {
            "playerID": "123"
        },
        {
            "playerID": "456"
        },
        {
            "playerID": "789"
        }
    ]
}
     

For more example use cases, see Example Game Use Cases.