Starting with this article, I’m going to look at the methods concerned with photos, namely:
* photos_get
* photos_getAlbums
* photos_getTags
In this article, I’ll look at the
photos_getAlbums method.
photos_getAlbumsThe
photos_getAlbums method retrieves information about photo albums. It can:
* Retrieve information about a given user’s photo albums
* Retrieve information about any number of photo albums, given the photo albums’ IDs
In Facebook, photos don’t just exist on their own — every photo has to belong to an album. That’s why I’m covering this method first.
Inputphotos_getAlbums takes two arguments — here’s its signature:
photos_getAlbums($uid, $aids)
The parameters it expects are explained below:
| Parameter | What It Is |
| $uid | [optional][integer] The ID of the user whose photo albums are to be retrieved. If no value is provided, the current user's photo albums will be retrieved. |
| $aids | [optional][array of integers] An array containing the IDs of phpto albums to retrieve. If no photo album IDs are given, the method will fetch all the albusm for the user specified in $uid. |
Outputphotos_getAlbums returns an array of associative arrays, with one element for each photo album. The associative array in each element is explained in the table below:
| Array Element | What It Is |
| aid | Album ID - the unique identifier for the photo album. |
| cover_pid | Cover photo ID - the unique identifier for the album photo that will be used as the "cover" for the album. |
| owner | Owner ID - the ID of the user who owns the photo album. |
| name | The name of the photo album. |
| created | The date and time the photo album was created, expressed as a Unix timestamp in UTC time. |
| modified | The date and time the photo album was last modified, expressed as a Unix timestamp in UTC time. |
| description | A brief description of the photo album. |
| location | Text that explains where the photos in the album were taken. |
| link | The URL for the photo album's main page. Note: Unlike users and groups, you can't deduce a photo album's URL from its album ID. This is because the album ID isn't used as a parameter for an album's URL.
|
| size | The number of photos in the album. |
Getting the Current User’s Photo AlbumsLet’s start with the simplest case, in which we want to retrieve information about the current user’s photo albums. Calling
photos_getAlbums without any arguments does the job:
<?php
require_once 'appinclude.php';
echo("<pre>");
print_r($facebook->api_client->photos_getAlbums());
echo("</pre>");
?>
Here’s the output of that code, with me as the logged-in user. Naturally, your results will look different:
Array
(
(
[aid] => 2421870240750155075
[cover_pid] => 2421870240751164382
[owner] => 563885607
[name] => Toronto, a.k.a. Accordion City
[created] => 1187711532
[modified] => 1187711589
[description] => Random shots of mine from in and around Toronto.
[location] => Toronto
[link] =>
http://www.facebook.com/album.php?aid=46403&id=563885607 [size] => 1
)
[1] => Array
(
[aid] => 2421870240750135353
[cover_pid] => 2421870240750672685
[owner] => 563885607
[name] => Graphic Design Noodling
[created] => 1181323540
[modified] => 1181323664
[description] =>
[location] =>
[link] =>
http://www.facebook.com/album.php?aid=26681&id=563885607 [size] => 1
)
[2] => Array
(
[aid] => 2421870240750127055
[cover_pid] => 2421870240750480103
[owner] => 563885607
[name] => Accordion Hijinx
[created] => 1178156059
[modified] => 1181312653
[description] =>
[location] =>
[link] =>
http://www.facebook.com/album.php?aid=18383&id=563885607 [size] => 41
)
[3] => Array
(
[aid] => 2421870240750118761
[cover_pid] => 2421870240750303070
[owner] => 563885607
[name] => Pics of My Friends
[created] => 1174674516
[modified] => 1178594382
[description] => Interesting or funny photos featuring my friends. Maybe you're in here!
[location] =>
[link] =>
http://www.facebook.com/album.php?aid=10089&id=563885607 [size] => 30
)
[4] => Array
(
[aid] => 2421870240750127403
[cover_pid] => 2421870240750487641
[owner] => 563885607
[name] => Geekin' Out
[created] => 1178317424
[modified] => 1178317504
[description] => Random photos from geeky events, conferences and so on.
[location] =>
[link] =>
http://www.facebook.com/album.php?aid=18731&id=563885607 [size] => 1
)
)
Getting the Photo Albums of a Specified UserIn order to retrieve information about all the photo albums belonging to a user who isn’t the current user, you need to specify that user’s ID in the
$uid parameter and set the
$aids parameter to
NULL (or simply don’t provide any value for it).
Let’s get a look at Robert Scoble’s photo albums. His user ID is
501319654, so the code to retrieve his photo albums looks like this:
<?php
require_once 'appinclude.php';
echo("<pre>");
print_r($facebook->api_client->photos_getAlbums(501319654));
echo("</pre>");
?>
Here are the results — it looks as though he’s got only one publicly viewable album:
Array
(
(
[aid] => 2153151518772038259
[cover_pid] => 2153151518772126717
[owner] => 501319654
[name] => Robert Scoble's photos
[created] => 1180999046
[modified] => 1184371254
[description] => My photos
[location] => Half Moon Bay, CA
[link] =>
http://www.facebook.com/album.php?aid=2675&id=501319654 [size] => 49
)
)
Getting Information About One or More Arbitrary Photo AlbumsFinally, let’s retrieve information about a couple of photo albums whose IDs are known. In this case, we specify the albums’ IDs in the $aids parameter and set the $uid parameter to NULL.
Suppose we want to fetch information about these two photo albums:
* My “Accordion Hijinks” photo album, whose ID is
2421870240750127055 * Robert Scoble’s photo album, whose ID is
2153151518772038259<?php
require_once 'appinclude.php';
echo("<pre>");
print_r($facebook->api_client->photos_getAlbums(NULL, array('2421870240750127055', '2153151518772038259')));
echo("</pre>");
?>
Note that in the code, I put the photo album IDs in quotes. That’s because although the IDs are numeric, they’re too large to be represented as integers.
Here’s the output of the code:
Array
(
(
[aid] => 2421870240750127055
[cover_pid] => 2421870240750480103
[owner] => 563885607
[name] => Accordion Hijinx
[created] => 1178156059
[modified] => 1181312653
[description] =>
[location] =>
[link] =>
http://www.facebook.com/album.php?aid=18383&id=563885607 [size] => 41
)
[1] => Array
(
[aid] => 2153151518772038259
[cover_pid] => 2153151518772126717
[owner] => 501319654
[name] => Robert Scoble's photos
[created] => 1180999046
[modified] => 1184371254
[description] => My photos
[location] => Half Moon Bay, CA
[link] =>
http://www.facebook.com/album.php?aid=2675&id=501319654 [size] => 49
)
)
Next Time…In the next article, I’ll cover the photos_get method.
This material is a property of Joey deVilla. Please,
visit his great blog for more Facebook stuff.