Created
December 8, 2017 04:36
-
-
Save tracer8/649477036402d07584722ea13653fa0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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