2013-03-08 26 views
4

A組的第一個帖子中,我有一組在Facebook在用戶發佈有趣的圖片。我正在開發一個網站,以更有組織和有趣的方式呈現發佈的圖片。如何獲得使用Facebook的圖形API

我的做法是使用Facebook OpenGraph API。 我想知道我如何獲得第一篇文章。例如:前10個職位。

默認情況下,圖形API(https://graph.facebook.com/{group_id}/feed/)返回最後排序條件的職位。

我已閱讀網頁約分頁(http://developers.facebook.com/docs/reference/api/pagination/)。所以,我知道offsetlimit參數。

回答

1

有似乎沒有排序以任何其他順序進料的方法。

唯一的辦法我可以看到它下載整個飼料,並採取你所需要的...

// Set your access token here... 
$accessToken = 'XXX'; 

// Set your GroupID here... 
$groupId = '123'; 

// Set the number of feed items required here... 
$qtyRequired = 10; 

$url = 'https://graph.facebook.com/v2.2/' . $groupId . '/feed/?limit=100&access_token=' . $accessToken; 
$feed = array(); 

while ($url) { 
    // Get the data from Facebook. 
    $curl = curl_init(); 
    curl_setopt_array($curl, array(
     CURLOPT_RETURNTRANSFER => 1, 
     CURLOPT_URL => $url 
    )); 
    $data = json_decode(curl_exec($curl)); 

    // Store the feed to $feed. 
    if (is_array($data->data)) $feed = array_merge($feed, $data->data); 

    // Load the next page or quit. 
    if (isset($data->paging->next)) $url = $data->paging->next; 
    else $url = false; 
} 

// Feed will contain the oldest feed items. 
$feed = array_slice($feed, -$qtyRequired); 

您可能能夠通過指定你所需要的具體領域加快步伐。