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

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