12.16.2010

Facebook Connect NIGHTMARE Before Xmas (try integrating with Posterous!) ONLY! Payoff Below

We support different connection types for different objects. For example, you can get the list of all the people attending the Facebook Developer Garage at SXSW (ID #331218348435) by fetching https://graph.facebook.com/331218348435/attending?access_token=....

All of the different types of objects and connections we support are included in the Graph API reference documentation.


Authorization

The Graph API as such allows you to easily access all public information about an object. For example, https://graph.facebook.com/btaylor (Bret Taylor) returns all the public information about Bret. For example a user's first name, last name and profile picture are publicly available.

To get additional information about a user, you must first get their permission. At a high level, you need to get an access token for the Facebook user. After you obtain the access token for the user, you can perform authorized requests on behalf of that user by including the access token in your Graph API requests:

https://graph.facebook.com/220439?access_token=...

For example https://graph.facebook.com/btaylor?access_token=... (Bret Taylor) returns additional information about Bret Taylor.

The Graph API uses OAuth 2.0 for authorization. Please read the authentication and authorization guide which provides details of Facebook's OAuth 2.0 implementation, how to request permissions from a user and obtain an access token.

Getting an access token for a user with no extended permissions allows you to access the information that the user has made available to everyone on Facebook. If you need specific information about a user, like their email address or work history, you must ask for the specific extended permissions. You can learn about permissions you need, to access each property and connection of an object from the Graph API reference documentation.

Page impersonation

You can impersonate pages administrated by your users by requesting the "manage_pages" extended permission.

Once a user has granted your application the "manage_pages" permission, the "accounts" connection will yield an additional access_token property for every page administrated by the current user. These access_tokens can be used to make calls on behalf of a page. The permissions granted by a user to your application will now also be applicable to their pages.

Authenticating as an Application

To make administrative calls that do not require an active user (for example, retrieving analytics data or test users) you need to obtain an access token for your application. Read more about how to get an application access token here.


Reading

The Graph API allows you to read properties and connections of the Facebook social graph. You can use the API to read specific fields, get pictures of any object, introspect an object for metadata and get real-time updates on any changes.

Selection

By default, most object properties are returned when you make a query. You can choose the fields (or connections) you want returned with the "fields" query parameter. For example, this URL will only return the id, name, and picture of Ben: https://graph.facebook.com/bgolub?fields=id,name,picture

You can also request multiple objects in a single query using the "ids" query parameter. For example, the URL https://graph.facebook.com?ids=arjun,vernal returns both profiles in the same response.

The "ids" query parameter also accepts URLs. This is useful for finding IDs of URLs in the Open Graph. For example: https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/

Additionally, there is a special identifier me which refers to the current user. So the URL https://graph.facebook.com/me returns the active user's profile.

Pictures

You can render the current profile photo for any object by adding the suffix /picture to the object URL. For example, this will render your public profile photo:

<img src="https://graph.facebook.com/sobachemyaso/picture"/>

The same URL pattern works for all objects in the graph:

You can specify the picture size you want with the type argument, which should be one of square (50x50), small (50 pixels wide, variable height), and large (about 200 pixels wide, variable height): http://graph.facebook.com/sobachemyaso/picture?type=large.

Paging

When querying connections, there are several useful parameters that enable you to filter and page through connection data:

Introspection

The Graph API supports introspection of objects, which enables you to see all of the connections an object has without knowing its type ahead of time. To get this information, add metadata=1 to the object URL, and the resulting JSON will include a metadata property that lists all the supported connections for the given object. For example, you can see all the connections for the Developer Garage event above by fetching https://graph.facebook.com/331218348435?metadata=1. That outputs:

{ "name": "Facebook Developer Garage Austin - SXSW Edition", "metadata": { "connections": { "feed": "http://graph.facebook.com/331218348435/feed", "picture": "https://graph.facebook.com/331218348435/picture", "invited": "https://graph.facebook.com/331218348435/invited", "attending": "https://graph.facebook.com/331218348435/attending", "maybe": "https://graph.facebook.com/331218348435/maybe", "noreply": "https://graph.facebook.com/331218348435/noreply", "declined": "https://graph.facebook.com/331218348435/declined" } } }

The introspection feature is a useful and extensible way to find all the things your users are connected to.

Real-Time updates

Real-time updates provide you the ability to receive updates about all of your application's users, as their data changes. With such subscriptions, you can be confident that your cached data is correct without polling Facebook's servers, increasing the reliability of your application, and the responsiveness of your user experience.


Searching

You can search over all public objects in the social graph with https://graph.facebook.com/search. The format is:

https://graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE

We support search for the following types of objects:

You can also search an individual user's News Feed, restricted to that user's friends, by adding a q argument to the home connection URL:

http://whatgetsmehot.posterous.com/facebook-connect-nightmare-before-xmas-try-in from