Skip to content

Instantly share code, notes, and snippets.

@abeMedia
Last active Aug 29, 2015
Embed
What would you like to do?
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