Skip to content

Instantly share code, notes, and snippets.

@pingyen
Last active August 29, 2015 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pingyen/55a009262c5b1936828f to your computer and use it in GitHub Desktop.
Save pingyen/55a009262c5b1936828f to your computer and use it in GitHub Desktop.
Download Facebook Group Feed, Memebers, & About
<?php
ini_set('date.timezone', 'Asia/Taipei');
$access_token = isset($argv[1]) ? $argv[1] : 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456';
$group_id = 123456789012345;
/* 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/$group_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);
/* members */
$json = file_get_contents("https://graph.facebook.com/$group_id/members?limit=1000000&access_token=$access_token");
if (strlen($json) > 0) {
file_put_contents(__DIR__ . '/members/' . date('YmdHis') . '.json', $json);
}
/* about */
$json = file_get_contents("https://graph.facebook.com/$group_id/?access_token=$access_token");
if (strlen($json) > 0) {
file_put_contents(__DIR__ . '/about/' . date('YmdHis') . '.json', $json);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment