Facebook Development for Websites – Graph API Introduction
The graph API is one of the new application programming interfaces launched by Facebook to replace the old RESTful API.
The graph API allows developers to tap into the ‘social graph’ and retrieve information from Facebook. It can be used to retrieve public information and also, with the appropriate permissions, more personal information, information about your friends, employment – basically anything that you share to the public or explicitly authorise the app or website to access.
The graph API is not just limited to people and their profiles on Facebook. It can also be used to access things such as events, pages and groups. If it is on Facebook, then chances are you can access and retrieve the information using the graph API.
The ‘social graph’ on Facebook contains everything within the ‘Facebook world’ and how it connects and relates to each other. You can get information on who is friends with who, who is attending which events, and who likes a particular celebrity.
Facebook treats all these different types of information as ‘objects’. There are different types of objects but essentially, everything within the world of Facebook is an object and it is assigned its own unique ID which, as the name suggest, uniquely identifies an individual object.
Data that is retrieved from Facebook is in a JSON (JavaScript Object Notation) format. This is a widely used and standardised format which has become commonplace for applications and websites sharing information over the Internet. Many programming languages will have support for JSON data types and will contain functions which can change the data into a standard format for that programming language.
For example, if you are using ColdFusion, then the JSON data returned by Facebook to your website is essentially, to all intents and purposes, as far as ColdFusion is concerned, a long string with delimiters. In ColdFusion, this makes the data hard to work with. It would be easier if it was a structure, with appropriately named attributes. That’s no problem, ColdFusion includes a very handy function called ‘DeserializeJSON’. This function can convert the returned data into an array (structure) of appropriately named attributes ready for you to use and manipulate within your application or website.
An example of the data returned by Facebook from a request to the Graph API is shown below:
{
“name”: “Facebook Platform”,
“website”: “http://developers.facebook.com”,
“username”: “platform”,
“founded”: “May 2007”,
“company_overview”: “Facebook Platform enables anyone to build…”,
“mission”: “To make the web more open and social.”,
“products”: “Facebook Application Programming Interface (API)…”,
“likes”: 449921,
“id”: 19292868552,
“category”: “Technology”
}
(Facebook, no date).
The example above shows the returned public data about the Facebook Platform page. It describes the general attributes and information of the page. This can be used in data on your own website or it can be used in part or whole in your own functions and calculations.
The graph API can be used to access many items including:
- Users
- Pages
- Events
- Groups
- Applications
- Status Messages
- Photos
- Photo Albums
- Profile Pictures
- Videos
- Notes
- Checkins
The power of the Graph API cannot be overstated – when integrated correctly into a quality third party application, its full power can be realised and your application or website can be instantly taken from being standalone, to fully integrated with the Facebook website (and its many millions of users).