Last active
August 29, 2015 14:13
-
-
Save abemedia/952b3688e6e7cb86b12e to your computer and use it in GitHub Desktop.
Get all Facebook albums & photos of a user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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