facebookfacebook-instant-games

Storing additional information for Facebook Instant Game leaderboard


I wanted to make an object that is independent of the Facebook leaderboard and can be accessed and updated by all the users for a Facebook instant game. Can this be achieved by using only Facebook's server?


Solution

  • At this point this can only be accomplished via a server side integration. Instant Games provides three mechanisms to store data:

    Leaderboards: clearly according to your post you're already using these, but I did want to add that you can store additional data in a leaderboard as well as a simple score. Each score can have an object with key value pairs associated with it for additional information.

    FBInstant.getLeaderboardAsync('my_leaderboard')
      .then(function(leaderboard) {
        return leaderboard.setScoreAsync(42, '{race: "elf", level: 3}');
      })
    

    Player Data: a player can have data stored for them that is not accessible to other players.

    FBInstant.player
      .setDataAsync({
        achievements: ['medal1', 'medal2', 'medal3'],
        currentLife: 300,
      })
    

    Player Stats: A player can also have stats stored for them that are not accessible to other players. The main difference between player stats and player data is that stats support an atomic increment operation, and in future may be shown outside of the game (e.g. on a Facebook user's profile).

    FBInstant.player
      .setDataAsync({
        achievements: ['medal1', 'medal2', 'medal3'],
        currentLife: 300,
      })
    

    Other kinds of data we are considering include context data, which would be tied to a context. We are currently not investigating adding any type of global data blob, as these tend to have lots of synchronization problems in general and cannot easily be generalized.

    It would be interesting to learn more about your use case to see if it is something we could support in future.