Package: fb
fbis a python sdk for the Facebook Graph Api. The sdk provides three methodsfor interacting largely with facebook. publish(), get_object() and delete()In addtion to the three, there is one helper method to view the structure ofobjects returned from facebook, show_fields()Installationsudo pip install fb1. Publishing to FacebookFor publishing, use the publish() method.  Publishing means creating objects like:a wall post, a like, events and albums, etc. Currently photo uploadis not supported. The method returns the id of the object created.Atdevelopers.facebook.com/docs/reference/api/publishing/under‘Other  Objects’, see list of publish categories except “photos”.Examplesimport fb# Go todevelopers.facebook.com/tools/explorerto generate test tokentoken=”the facebook token you are going to use”facebook=fb.graph.api(token)#Post on the current user’s wallfacebook.publish(cat=”feed”, id=”me”, message=”My facebook status”)#Like an object(wall post, photo and anything thats likable in facebook) with id=object_idfacebook.publish(cat=”likes”, id=object_id)#Comment on an objects thats commentablefacebook.publish(cat=”comments”, id=object_id, message=”My comment”)#Create an albumfacebook.publish(cat=”albums”, id=”me”, name=”Album Name”, message=”Album Details”)Create an eventfacebook.publish(cat=”events”, id=”me”, name=”My Event”, start_time=”2013-10-16-12:20”, end_time=”2013-10-18-14:30” )ImportantIn addition to ‘cat’ (the category)  and ‘id’, publish takes any parameter thatsvalid for the publish category(cat). Like “message” for wall post, “name” for albums,nothing for likes, etc. Check facebook doc for full list of valid parametersfor each kind of publishing. If you find that a parameter is raising error,it maybe because this sdk does not yet support the parameter,please report such casesto the author.2. Fetch Objects from FacebookObjects can be fetched in two ways using the get_object() method.Fetch “single” object with  it’s given “fields”  passed in a list.Or retrieve “multiple” objects passed with their “ids” in a list.The method returns the object as python dictionary containing related fieldsExamples#Retrieve given fields for a single objectobject=facebook.get_object(cat=”single”, id=object_id, fields=[“name”, “email” ] )#Retrieve ALL fields for a single objectobject=facebook.get_object(cat=”single”, id=object_id, fields=[ ] )#Rertieve multiple objectsobject=facebook.get_object(cat=”multiple”, ids=[‘zuck’, ‘me’] )3. Delete ObjectsDeleting objects is simple. use the delete method and pass the id of theobject to be deleted. Note that a “like” has no id in facebook, so in case of deletinga “LIKE”, you have to pass the id of the object liked and the category of the deletewhich is “likes”.Examples#Delete a statusfacebook.delete(id=status_id)#Delete a commentfacebook.delete(id=comment_id)#Delete a “LIKE”facebook.delete(cat=”likes”, id=object_id)4. The Helper MethodsAs of version 0.4.0, there is one helper method,show_fields(). Using this method,it is possible to view the structure of the objects returned by facebook. This will helpfurther manipulate the fetched objects for individual needs.Examples#Get “friends” and “education” of the current userfriends_and_education=facebook.get_object(cat=’single’, id=’me’, fields=[‘friends’, ‘education’])#Display the Structure of the object returned from facebook graphfacebook.show_fields(friends_and_education)The method will print the following:______________________education(list)schoolidnametypeyearidnamefriendspagingnextdata(list)nameidid_______________________The above are all dictionary keys with sub-keys. Some of the keys are prefixed by “(list)”which means their values are saved inside a list and should be accessed through indexing.In line with the structure  printed by the  method, we can access various parts of the objectfetched from facebook as shown below# “name” of schools attendedfriends_and_education[‘education’][0][‘school’][‘name’]friends_and_education[‘education’][1][‘school’][‘name’] and so on……..# “type” of the nth school in the objectfriends_and_education[‘education’][n][‘type’]#”name” of the nth friend in the objectfriends_and_education[‘friends’][‘data’][n][‘name’]#”name” and “id” of all friendsfriends_and_education[‘friends’][‘data’]Note:The idea behind introducing the show_fields() method is to help developersget a visual overview of the internal structure of objects retrieved from facebook graphso that they can write their own methods easily to further meet their needs.Reporting issuesPlease report bugshere. Or email toblaklites@gmail.com