I am trying to retrieve a player score using facebook API in Unity. This is the code that I am using:
if (FB.IsLoggedIn) {
FB.API("/me/scores", Facebook.HttpMethod.GET, scoreRetrieved);
}
public void scoreRetrieved(FBResult result) {
var dict = Json.Deserialize(result.Text) as Dictionary<string,object>;
print (dict["score"]);
}
and this is the result of FBResult result.text :
{"data":[{"user":{"id":"1000015239203","name":"AAA BBB"},"score":30,"application":{"name":"game","id":"2419296161993"}}]}
How can I access the score? It's not working for me a have an error because the key doesn't exist!
it was painfull but i found a solution:
public void scoreRetrived(FBResult result){
var dict = Json.Deserialize(result.Text) as Dictionary<string,object>;
List<object> data = dict["data"] as List<object>;
int playerScore = int.Parse(((Dictionary<string, object>)data.ToArray()[0])["score"].ToString());
}
wow finally !!