【问题标题】:How to get the very first posts of a Group using Facebook Graph API如何使用 Facebook Graph API 获取群组的第一个帖子
【发布时间】:2013-03-08 08:58:40
【问题描述】:

我在 Facebook 上有一个用户发布有趣图片的群组。我正在开发一个网站,它将以更有条理和有趣的方式展示发布的图片。

我的方法是使用 Facebook OpenGraph API。 我想知道如何获得第一个职位。例如:前 10 个帖子。

默认情况下,图形 API (https://graph.facebook.com/{group_id}/feed/) 返回从 LAST 到 FIRST 排序的帖子。

我已阅读有关分页的页面 (http://developers.facebook.com/docs/reference/api/pagination/)。所以,我知道offsetlimit 参数。

【问题讨论】:

    标签: php facebook facebook-graph-api


    【解决方案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);
    

    您可以通过指定所需的确切字段来加快速度。

    【讨论】:

      猜你喜欢
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 2016-06-01
      • 2018-04-27
      • 1970-01-01
      • 2020-07-08
      相关资源
      最近更新 更多