Skip to content

Instantly share code, notes, and snippets.

@pingyen
Last active August 29, 2015 14:20
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 pingyen/d1dc34cadcbd76bc1338 to your computer and use it in GitHub Desktop.
Save pingyen/d1dc34cadcbd76bc1338 to your computer and use it in GitHub Desktop.
Download Facebook User Feed
<?php
$access_token = isset($argv[1]) ? $argv[1] : 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456';
$user_id = 'me';
/* feed */
$until = time();
$since = intval(substr(array_values(array_filter(scandir(__DIR__ . '/feed/', true), function($val) { return substr($val, -5) === '.json'; }))[0], 0, -5));
$limit = 500;
$url = "https://graph.facebook.com/$user_id/feed?until=$until&since=$since&limit=$limit&access_token=$access_token";
do {
$json = file_get_contents($url);
$data = json_decode($json, true);
if (isset($data['paging']) === false) {
break;
}
file_put_contents(__DIR__ . "/feed/$until.json", $json);
$url = $data['paging']['next'];
parse_str(parse_url($url, PHP_URL_QUERY), $paras);
$until = intval($paras['until']);
} while (true);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment