Code: Select all
//get the Player's friends' IDs (friends who have also played this game)
public void GetIDsOfFriends(Action OnComplete, Action NoInternet)
{
//if the Player's friends' ID have already been retrieved from Facebook
if (Score.friendIDs.Count > 0)
{
OnComplete();
return;
}
string query = "me/friends";
FB.API(query, HttpMethod.GET, result =>
{
var dictionary = new Dictionary();
Debug.Log("fb api working");
try
{
Debug.Log("trying to read dictionary");
dictionary = (Dictionary)Facebook.MiniJSON.Json.Deserialize(result.RawResult);
}
catch (OverflowException)
{
NoInternet();
return;
}
Debug.Log("raw result: " + result.RawResult);
var friendsList = (List)dictionary["data"];
foreach (var dict in friendsList)
{
var friendName = ((Dictionary)dict)["name"].ToString();
//print the friend name in the log
Debug.Log("friend name: " + friendName);
var friendId = ((Dictionary)dict)["id"].ToString();
Debug.Log("friend ID: " + friendId);
//add the ID to the Score class
Score.friendIDs.Add(friendId);
}
//execute OnComplete once all the friends' IDs are in the Score.friendsIDs variable
OnComplete();
});
}