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