Getting data from the Facebook Graph API + a script

Screenshot-Facebook Developers - Google Chrome

After the last few weeks spent on tweaking the tools for data-grabbing on Sina Weibo and Twitter, we’re now moving on to Facebook. Or going back to it, as this was what I was on before focusing on the microblogs.

Python script to get data from the Facebook Graph API:

Facebook has a very interesting API, which it dubs its Graph API. It basically models all entities of Facebook, let them be users (people), events, pages, groups, but also stuff like your links or even Facebook messages “mail” as nodes of Mark Zuckerberg’s wacky vision of organising the world’s social information as points and arrow, or rather vertices and edges in graph theory. It’s people and things and their connections, sitting in a database and rendered as the interface of or on your mobile device or more eventually (a sky map of Facebook, anyone?).

Basically, just like for Twitter and Sina Weibo’s open APIs, you can use Facebook’s API to access the same information you would be able to see as a normal user and perhaps retrieve it to your local storage for future use, for comparisons over time or other analysis that are more practical to do on your local server. Only this time, you can automate the process and do it without involving web crawlers — those are not tailor-made, and the API provides a single standard format, JSON.

Without even logging in, you can already get information our of searches on the Graph API (see Openbook’s experiment). For instance, a search on Hong Kong gives you this: If you knew my Facebook username, then you could point to the Graph API and get my basic info: full name, username, locale, gender ( All of this is not very special: it’s just the same data that you could get on a search on Google without logging in to Facebook.

What becomes powerful is when you get an access token (associated with a dummy app that you presumably created), after following the instructions on the documentation, which allows you to navigate the same data as a logged in user. It’s becoming interesting, because you can then navigate data like membership to groups (how about co-membership?) or let’s say the popularity of a link that was shared across Facebook by different users. That’s very interesting for social network analysis.

In any case, I started writing a Python script to try to manage the different use cases of the Graph API to either output to CSV or store in a PostgreSQL database. I am posting here a first almost-vanilla version of this on our GitHub:

Leave a Reply