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

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