2

in v6.x to get score I was using

FB.API("/me/scores", HttpMethod.GET, LoadScoreCallback)

where LoadScoreCallback used FBResult. Since FBResult has been replaced by IGraphResult in 7.x, I am unable to get my score through it. Does anyone know how to do that?

chanfort
  • 125
  • 1
  • 1
  • 9

1 Answers1

4

The IGraphResult returned from an FB.API call to "/me/scores" has the scores data as you would expect in v7.x+

Here is example code for parsing the result (note: You should add error-handling):

void handleScoresResponse (IGraphResult result)
{
    UnityEngine.Debug.Log(result.RawResult);

    var dataList = result.ResultDictionary["data"] as List<object>;
    var dataDict = dataList[0] as Dictionary<string, object>;

    long score = (long)dataDict["score"];
    var user = dataDict["user"] as Dictionary<string, object>;

    string userName = user["name"] as string;
    string userID = user["id"] as string;

    UnityEngine.Debug.Log(userName + ": " + score);
}

See: Facebook Unity SDK Sample usage of me/scores

zzzzzz
  • 493
  • 2
  • 12
  • Oh, I see, you were using built in example scenes to get Log printed out. Also nice to see `result.RawResult`, as it prints out the whole structure. It's also interesting to see that it is not needed anymore to use `Json.Deserialize` calls in this case. Thanks a lot. – chanfort Nov 09 '15 at 20:13
  • By the way, is it really score data storied in a `long` format instead of regular `int` ? – chanfort Nov 09 '15 at 20:32
  • @chanfort the `long` format is due to the way the `Json` class deserializes, you can always cast it to an `int` discarding any MSBs. – zzzzzz Nov 09 '15 at 23:48
  • I was wondering if I would keep it as `long` all the time, i.e. if I would like to save very large score, let say 16 significant digits, would it be working? – chanfort Nov 10 '15 at 01:34
  • On Facebook's side it looks to be a unsigned 32bit int, you can test this yourself easily with the Graph API Explorer. Submitting 4294967295 the maxValue for uint works, but add +1 and it fails: https://developers.facebook.com/tools/explorer/?method=POST&path=me%2Fscores&version=v2.5&score=4294967295 – zzzzzz Nov 11 '15 at 00:37