Created
March 30, 2012 23:56
-
-
Save kenmickles/2257988 to your computer and use it in GitHub Desktop.
Download all Facebook photos of somebody
This file contains 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 | |
// 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