Last active
August 29, 2015 14:20
-
-
Save pingyen/d1dc34cadcbd76bc1338 to your computer and use it in GitHub Desktop.
Download Facebook User Feed
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 | |
$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