Need help getting Prime31 getFriends Facebook event listener to work

Has anyone managed to get Prime31’s social networking plugin to work when it comes to getting the facebook friends list into a usable form?

I call Facebook.instance.getFriends(OnGetFriendsComplete);

Then the listener event gets called and is passed an OBJECT that contains all the friends info. Problem is I don’t know how to parse the Object into a list of ID’s and Names. Here is my code that does not work, I’m stuck once I get the dictionary entry for “data”

 void OnGetFriendsComplete(string error,object result)
  {
    if(error != null)
      D.logx("Error= {0}",error);
    else
    {
      Prime31.Utils.logObject(result);
   
      var ht = result as IDictionary;
      
      foreach(var key in ht.Keys)
      {
        if(key.ToString() == "data")
        {
          // data entry found but now what?
          
          break;
        }
      }
 
    }
  }

the logObject function prints this to the console but without the source code for logObject I don’t know how to do the same task

--------- IDictionary ---------

 --------- IList ---------
data: 
	 --------- IDictionary ---------
	id: 	574738222
	name: 	Bolly Wood
	 --------- IDictionary ---------
	id: 	609976923
	name: 	Pair Nowler
	 --------- IDictionary ---------

Haha, I had fun doing exactly this. I think I unwrapped this layer by layer using reflection to find out what something was, then writing another layer of code to find out what the children were, repeating until I finally got all the way to the leaf nodes.

If I remember I’ll post up some code when I get home.

Man oh Man! This is exactly what I just had to do! I had to first print out what type object was and it was a hash table, then cast it to the hashtable, then the result back into an object to find out its type, then keep repeating the process until I’d drilled down into the data. What a pile of crap, purchased plugins should make your life easier not harder! Anyway here is my code to extract the ID’s from a friends list just in case it helps someone else.

void OnGetFriendsComplete(string error,object result)
  {
    string id;
    Hashtable ht2;

    if(error != null)
      D.logx("Error= {0}",error);
    else
    {
      //Prime31.Utils.logObject(result);
  
      Hashtable ht = result as Hashtable;
      ArrayList list = ht["data"] as ArrayList;

      for(int i = 0; i < list.Count; i++)
      {
        ht2 = list[i] as Hashtable;
        id = ht2["id"] as string;
        D.logx("ID = {0}",id);
      }
    }
  }

Looks like you don’t need my code then. Glad you figured it out!

Very helpful. Thanks for sharing.

@arkon, besides actually making your game for you I’m not really sure how to make this much easier. The plugin even provides a handy logObject method that dumps the entire object to the console in a nice easy to read format with all the sub object types right there for you. And if you want to take it even further the plugin even contains a full deserialization system so that in a couple lines of code you can have strongly typed data from any Graph API calls: http://m.youtube.com/results?q=prime31studios%20facebook&search_sort=relevance&search_type=search_all&uploaded=&oq=prime31studios%20facebook&gs_l=youtube-reduced.3...12887.14551.0.14829.8.8.0.0.0.0.102.735.6j2.8.0....0...1ac.1.23.youtube-reduced..8.0.0.R731S22A6bY#/watch?v=z0-rVwn1WCo and http://m.youtube.com/user/prime31studios#/watch?v=UyElIr-hsmY

@Prime31 Clearly based on this thread and others Ive read when trying to figure this out, its not as easy as you think it is for quite a lot of people. I even saw a post with someone offering to pay for someone to help get this particular plugin to work for them. I have long since got it to work for me using the method I posted above but your example scene and lack of documentation with this and all of your plugins need a rethink I think.
Your example scenes whilst showing how each individual function works and the docs do the same dont really give much help in how to actually use them. What you call first and where etc. personally I think the socal plugin was the worst and even though I have it in use in a live game it leaves me with the feeling I have not done it correctly or could have integrated it better.

Your plugins all work great if the user has just one scene and just drops the prefabs in. As soon as you go multi scene you get left with listeners that get disabled leaving new users confused as to why none of the listeners work anymore. Mike I hate to nit pick as your plugins are essential but your docs assume your level of competency.

Just for people that have the same problem and haven’t figured it out yet, prime 31’s json is actually really nice to use once you know how to use it.
any object must be cast into a IDictionary
IDictionary dict = obj as IDictionary;
and the data can be accessed as
string str = dict[“name_of_var”].ToString();
any array must be cast into a IList
IList list = obj as IList;
and the data is accessed:
string str = list*.ToString();*
remember you can recast the result of a list or a dictionary if you have an array of objects:
IDictionary objectInArray = list as IDictionary;
This post although not directly related to the problem gives a really good example of how it works:
_*http://answers.unity3d.com/questions/570097/parsing-facebook-graph-json.html*_
My only wish is that what I just wrote would have been in the prime31’s documentation or even better in the example they provide with their product.

2 Likes

I need your code :confused: