Get Photos

Problem

I need to retrieve specific photos, either because they contain a specific user, are in a specific album, or I have their pids (photo IDs).

Solution

Use the Photos.get() method. To retrieve photos of a specific user, call:

$photos = $facebook->api_client->photos_get('561415460',null,null);

To retrieve photos from a specific album, get the aid using Photos.getAlbums() and then pass it as the middle parameter (note that the aid shown in the URL when you’re looking at a specific album isn’t the album’s real aid and won’t retrieve the photos here):

$photos = $facebook->api_client->photos_get(null,'1234567890123456789',null);

To retrieve specific photos, pass an array of aids as the final parameter:

$targetPhotos = array('1234567890123456789','9876543210987654321');
$photos = $facebook->api_client->photos_get(null,null,$targetPhotos);

You can combine the three parameters in any way you’d like, allowing you to filter for photos from specific albums that have been tagged with a specific user, or the subset of a specific set of photos that have been tagged with a specific user, etc.

Discussion

This method will return a multidimensional array of photo elements, each containing the following:

[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/ ...

Get Facebook Cookbook 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.