Skip to content

Instantly share code, notes, and snippets.

@tracer8
Created December 8, 2017 04:36
Show Gist options
  • Save tracer8/649477036402d07584722ea13653fa0f to your computer and use it in GitHub Desktop.
Save tracer8/649477036402d07584722ea13653fa0f to your computer and use it in GitHub Desktop.
// Query score
public void QueryScores(int limitUserQuery, Action<List<FacebookUserData>> callbackQueryScoreSuccessPost)
{
string apiCommand = string.Format("/app/scores?fields=score,user.limit({0})", limitUserQuery);
FB.API(apiCommand, HttpMethod.GET, QueryScoresCallback);
OnQueryScoreSuccess = callbackQueryScoreSuccessPost;
}
private void QueryScoresCallback(IGraphResult result)
{
if (result.Error != null)
{
#if UNITY_EDITOR
Debug.Log(result.Error);
#endif
return;
}
#if UNITY_EDITOR
Debug.Log(result.RawResult);
#endif
List<object> scoresGroup = null;
scoresGroup = FacebookApiUtil.DeserializeScores(result.RawResult);
List<FacebookUserData> userDatasGroup = new List<FacebookUserData>();
userDatasGroup = GetUserDatasGroup(scoresGroup);
if (OnQueryScoreSuccess != null)
OnQueryScoreSuccess(userDatasGroup);
}
private List<FacebookUserData> GetUserDatasGroup(List<object> scoresGroup)
{
List<FacebookUserData> userDataGroup = new List<FacebookUserData>();
foreach (object score in scoresGroup)
{
var entry = (Dictionary<string, object>)score;
var user = (Dictionary<string, object>)entry["user"];
FacebookUserData userData = new FacebookUserData();
userData.userId = user["id"].ToString();
userData.userName = user["name"].ToString();
userData.userScore = entry["score"].ToString();
userDataGroup.Add(userData);
}
return userDataGroup;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment