Facebook Cookbook - Jay Goldman [153]
$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 Pages, the equivalent query is:
SELECT fields FROM page WHERE page_id IN (SELECT page_id FROM page_fan
WHERE uid = $uid AND type = $type)
See Table 8-15 in Page Fan Table for more information.
Checking Page Properties
Problem
I need to find out if a user is the admin of a Page, or if a Page has my app installed, or whether a user is a fan of a specific Page.
Solution
Use the Pages.isAdmin() method to find out whether the current loggedinuser is an admin of a specific Page:
$result = $facebook->api_client->pages_isAdmin('123456789');
where 123456789 is the pageid of the Page you’re interested in.
Use the Pages.isFan() method to find out whether a user is a fan of a specific Page:
$result = $facebook->api_client->pages_isFan('123456789', '12345');
where 123456789 is the pageid of the Page you’re interested in, and 12345 is the optional uid of the user you want to check for (it defaults to the current loggedinuser if you leave it off).
Use the Pages.hasAppAdded() method to find out if a specific Page has your app added:
$result = $facebook->api_client->pages_hasAppAdded('123456789');
where 123456789 is the pageid of the Page you’re interested in.
Discussion
All three methods return true (1) if the thing you’re checking is true, or false (0) if it isn’t (or the pageid can’t be found).
Create a Photo Album
Problem
I need to create a photo album.
Solution
Use the Photos.createAlbum() method, which unfortunately isn’t supported in the PHP Client Library (see Adding Missing PHP Client Library Methods):
$album = $facebook->api_client->photos_createAlbum('Test Album',
'Testville','This is a test');
Discussion
This method will return an array containing the information about your newly created album:
Array
(
[aid] => 12345679012345
[cover_pid] => 0
[owner] => 12345
[name] => Test Album
[created] => 1212878578
[modified] => 1212878578
[description] => This is a test
[location] => Testville
[link] => http://www.facebook.com/album.php?aid=12345679012345&id=12345
[size] => 0
)
You’re allowed to store the aid (album ID) and the uid of the owner, but nothing else. The returned cover_pid value will always be 0 because this album was just created and doesn’t contain any photos yet.
Get Photo Albums
Problem
I need to retrieve a user’s photo albums.
Solution
Use the Photos.getAlbums() method:
$albums = $facebook->api_client->photos_getAlbums('12345');
You can specify a uid and/or an array of aids (album IDs) to retrieve specific albums:
$targetAlbums = array('9876543210987654321','12345');
$albums = $facebook->api_client->photos_getAlbums(null,$targetAlbums);
Specifying both will return only the albums from the list that belong to the user.
Discussion
This method will return a multidimensional array of photos, with each photo containing:
[0] => Array
(
[pid] => 1234567890123456789
[aid] => 9876543210987654321
[owner] => 1345
[src] => http://photos-f.ak.facebook.com/photos-ak-sf2p/
v283/16/97/12345/s....jpg
[src_big] => http://photos-f.ak.facebook.com/photos-ak-sf2p/
v283/16/97/561415460/n....jpg
[src_small] => http://photos-f.ak.facebook.com/
photos-ak-sf2p/v283/16/97/561415460/t....jpg
[link] => http://www.facebook.com/photo.php?pid=1122334&id=12345
[caption] =>
[created] => 1212879873
)
The created field is expressed in epoch seconds (see Formatting Relative Time for more information about epoch time).
Get Photos