Search code examples
c#facebookfacebook-graph-apifacebook-unity-sdk

FB.API invitable_friends return values


I am creating a custom UI panel for Facebook Invites on Unity for which I need all the names of the friends. This, I am trying to get to a Dictionary or any other data type. From the IResult object which I get from FB.API.

The query I used is as follows: FB.API("/me/invitable_friends?fields=id,name",HttpMethod.GET,GetUserFriends);

I get a Dictionary in the IResult object in which there is a key called "data" with all the friends stored in one object. My question is how do I get each of the friends into a Dictionary or any other type from the Object.

(PS. I am writing the code a in C# script)


Solution

  • Your IResult["data"] object is just of type object.

    What you want to do is then cast that object to be a Dictionary;

    (Dictionary<string, object>)result["data"]
    

    The above (I don't know what you called your result variable sorry, so I just called it result) should work.

    You'll then have to case each user again to a dictionary to get their information out in separate fields. Reading the documentation should help with finding out what fields the dictionary contains, or you can do a foreach loop and Debug.Log all of the dictionary keys.