Facebook Graph API:只能显示100个帖子


Facebook Graph API: Can only display 100 posts

我刚刚开始涉猎JSON和Facebook的Graph API。通过以下操作,我已经能够从我的Facebook页面中提取帖子:

$page_id = '???';
$access_token = '???';
$json_object = @file_get_contents('https://graph.facebook.com/' . $page_id . 
'/posts?access_token=' . $access_token . '&limit=100');
$fbdata = json_decode($json_object);
foreach ($fbdata->data as $post ) {
    $posts .= '<p><a href="' . $post->link . '">' . $post->story . '</a></p>';
    $posts .= '<p><a href="' . $post->link . '">' . $post->message . '</a></p>';
    $posts .= '<p>' . $post->description . '</p>';
    $posts .= '<br />';
}
echo $posts;

但是Facebook不允许在一个JSON请求中超过100个帖子。是否有一种方法可以通过提出多个请求来解决这个问题,或者我应该以完全不同的方式来处理这个问题?

有人知道我如何从我的Facebook页面显示所有现有的帖子吗?

无限数量的文章可以通过以下方式分页显示:

//Set page variable/page number
if($_GET['page'] == 0) {
    $page = 1;
}
else {
    $page = $_GET['page'];
}
//Page increments/decrements
$next_page = intval($page + 1);
$prev_page = intval($page - 1);
//Set offset if it isn't the first page
if ($page > 1) {
    $offset = $page * 5 - 5;
} 
//Facebook Dev details
$page_id = '???';
$access_token = '???';
//Get JSON for specified page
$json_object = @file_get_contents('https://graph.facebook.com/' . $page_id . 
'/posts?access_token=' . $access_token . '&limit=5' . '&offset=' . $offset);
//Interpret the data
$fb_data = json_decode($json_object);
foreach ($fb_data->data as $post ) {
    $posts .= '<p><a href="http://facebook.com/' . $post->id . '">' . $post->story . '</a></p>';
    $posts .= '<p><a href="http://facebook.com/' . $post->id . '">' . $post->message . '</a></p>';
    $posts .= '<p>' . $post->description . '</p>';
    $posts .= '<br />';
}
//Display posts
echo $posts;
//If page isn't the first page add previous button
if ($page > 1) {
    echo '<a href="?page=' . $prev_page . '">' . 'Previous' . '</a>';
} 
//Total offset of posts on next page
$next_page_offset = $offset + 5;
//Make next page object
$json_next_page_object = @file_get_contents('https://graph.facebook.com/' . $page_id . 
'/posts?access_token=' . $access_token . '&limit=5' . '&offset=' . $next_page_offset);
//Get JSON for next page
$fb_next_data = json_decode($json_next_page_object);
//Echo next button if size of next data is greater than one
if( sizeof( $fb_next_data->data) > 0 ) {
    echo '<a href="?page=' . $next_page . '">' . 'Next' . '</a>';
}

可能需要一些改进,但目前为止它工作正常。

我希望到目前为止我所得到的可以帮助其他人制作一个基本的和容易管理的Facebook动态:]