0
votes

I'm switching to Facebook Scores API for my mobile game's highscores. Like in this question, whose answer is not quite satisfying I would like to know how to seperate between:

  • Scores (The player finished a game and got a score below his actual highscore)
  • Highscores (The highscore of a particular player)

My current solution with Spring Social Facebook is:

MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>();
data.add("score", Integer.toString(score));
facebook.post("me", "scores", data);

The problem with this approach is:

I'm displaying a ranking for the user at the game-finished-screen by a comparison of his score to his friends scores via HTTP GET to GRAPH_API/APP_ID/scores Imagine a user finished a game with Score 100, but his current highscore is 500. When I post this new score to the facebook API, subsequent calls for getting the score comparison return 100 as score, rather than 500, which should be his actual highscore.

How should I solve this? Posting only the highscores to Facebook means that I can't compare the actual score from the game-finished-screen to the users friends. On the other hand, posting actual scores would make it neccessary to store the highscores somewhere else than Facebook, or resign from showing the user his highscore, which does not seem to be a good solution to me.

2

2 Answers

2
votes

I ended up checking if the current score is actually higher than the score on Facebook and only posting the new score if this check succeeds. Posting every score to Facebook does not work, because Facebook just saves the posted score and does not check if it is higher than the current uploaded score.

FacebookTemplate facebook = new FacebookTemplate(userAccessToken);
int highscore = queryScoreFromFacebook(facebook);
if (score > highscore) {
    MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>();
    data.add("score", Integer.toString(score));
    facebook.post("me", "scores", data);
}

// querying all scores for that player and his friends
List<Map<String, Object>> players = (List<Map<String, Object>>) facebook.fetchObject("/" + APP_ID + "/scores", Map.class).get("data");
1
votes

The Facebook Scores API only stores one (high) score per user and app at any time - if you want to track the score for other games you'll need to implement that yourself