Skip to content

Instantly share code, notes, and snippets.

@abemedia
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abemedia/952b3688e6e7cb86b12e to your computer and use it in GitHub Desktop.
Save abemedia/952b3688e6e7cb86b12e to your computer and use it in GitHub Desktop.
Get all Facebook albums & photos of a user
<?php
/**
* Get Facebook Open Graph data.
*/
function getdata($path) {
$url = "http://graph.facebook.com/$path";
$data = json_decode(file_get_contents($url));
return ($data->data?:$data);
}
$albums = getdata($_REQUEST['user'] . '/albums');
$data = [];
foreach ($albums as $key=>$album) {
$data[$key]['id'] = $album->id;
$data[$key]['title'] = $album->name;
$data[$key]['count'] = $album->count;
$data[$key]['image'] = getdata($album->cover_photo)->source;
$photos = getdata($album->id . '/photos');
foreach ($photos as $i=>$photo) {
$data[$key]['items'][$i]['title'] = $photo->name;
$data[$key]['items'][$i]['image'] = $photo->source;
}
}
header('Content-Type: application/json');
echo json_encode($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment