Skip to content

Instantly share code, notes, and snippets.

@kenmickles
Created March 30, 2012 23:56
Show Gist options
  • Save kenmickles/2257988 to your computer and use it in GitHub Desktop.
Save kenmickles/2257988 to your computer and use it in GitHub Desktop.
Download all Facebook photos of somebody
<?php
// the user's facebook ID
$facebook_id = 'zuck';
// an access token with access to that user's photos (grab one from https://developers.facebook.com/tools/explorer)
$access_token = '';
$url = 'https://graph.facebook.com/' . $facebook_id . '/photos?';
while ( true ) {
$request = $url . '&access_token=' . $access_token;
$response = json_decode(file_get_contents($request), 1);
// something went wrong
if ( !isset($response['data']) ) {
print_r($response);
break;
}
foreach ( $response['data'] as $photo ) {
$file_name = basename($photo['source']);
echo $file_name."\n";
$fp = fopen($file_name, 'w+');
$ch = curl_init($photo['source']);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
// all done
if ( !$response['paging']['next'] ) {
break;
}
$url = $response['paging']['next'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment