Selectively Querying Information with Property Selection

In the olden days of Facebook, API developers had to use a query language called Facebook Query Language (FQL) to selectively query results. Selectively querying results from Facebook API allowed developers to reduce the bandwidth that was necessary when making calls to get large data sets. This way, Facebook was only returning the information that developers absolutely needed.

To this day, FQL is still available and is not rumored to be going away anytime soon. (I cover FQL in the section, “Retrieving Advanced Data with FQL.”) However, you can selectively choose what you want returned to get the maximum bang for your buck using plain Graph API. Try this method first; then, if you need to get more specific (for example, joins), use FQL.

Using the IDs parameter to select more than one object

Selection in Graph API supports two ways to selectively choose information. The first is a way to select more than one object in a single request. You do this with the ids parameter appended to your Graph API call with a comma-separated list of the objects you want to have returned:

https://graph.facebook.com?ids=dummiesbook,stay

The URL GET request (that you can just paste into your Web browser for now) returns both Facebook Page objects for dummiesbook and stay in a JSON object that includes an array of two more JSON objects that include information about the two. The following code shows what this query would return:

{ "dummiesbook": ...

Get Facebook® Application Development For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.