O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Get Pages

Problem

I need to find all of the Pages that the current user is a fan of.

Solution

Use the Pages.getInfo() method:

$fields = array('name','pic_small','has_added_app');
$pages = $facebook->api_client->pages_getInfo(null,$fields,null,null);

Discussion

The four parameters are filters that allow you to constrain the result set. The first is for pageids (Page IDs), which allows you to retrieve info for a specific Page or a set of Pages:

$pages = array('25975037248', '5603889283');
$fields = array('name','pic_small','has_added_app');
$pages = $facebook->api_client->pages_getInfo($pages,$fields,null,null);

The second parameter is the set of fields you’d like returned in your results, which can include any of the fields listed in Table 8-15. The third is for uids and allows you to return the Pages for a different user (or set of users), provided that the current loggedinuser is allowed to see that info:

$users = array('567770429');
$fields = array('name','pic_small','has_added_app');
$pages = $facebook->api_client->pages_getInfo(null,$fields,$users,null);

The final parameter is for Page type and lets you filter the results down to a specified list. There doesn’t appear to be an easy way to get the list of possible types, but they are generally an all-uppercase version of the type’s name that you see when creating the page, with spaces replaced by underscores (e.g., “RETAIL”, “MUSICIAN”, “LOCAL_TECHNOLOGY_TELECOMMUNICATIONS_SERVICES”, etc.).

FQL equivalent

If you’d prefer to use FQL to access ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required