设置" / me / photos"的偏移/限制;在Facebook Graph API中调用

时间:2012-07-10 02:42:16

标签: php facebook facebook-graph-api facebook-php-sdk

这将返回按时间顺序排序的数组。如何为查询指定偏移/限制?

$photos = $facebook->api('me/photos');

1 个答案:

答案 0 :(得分:1)

订单基于created_time参数检查自己验证

http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fphotos%3Ffields%3Dcreated_time%2Cupdated_time

每个JSON响应结束时的分页属性允许您遍历集合。

"paging": {
    "previous": "https://graph.facebook.com/me/photos?fields=created_time\u00252Cupdated_time&value=1&redirect=1&limit=25&since=1341554766", 
    "next": "https://graph.facebook.com/me/photos?fields=created_time\u00252Cupdated_time&value=1&redirect=1&limit=25&until=1311564489"
  }

例如,要获取所有照片,

if($user_id) {
    $the_photos = array();

    $your_photos = $facebook->api("me/photos");

    while ($your_photos['data'])
    {
        $the_photos = array_merge( $the_photos, $your_photos['data'] );

        $paging = $your_photos['paging'];
        $next = $paging['next'];

        $query = parse_url($next, PHP_URL_QUERY);
        parse_str($query, $par);

        $your_photos = $facebook->api(
                "me/photos", 'GET', array(
                'limit' => $par['limit'],
                'until'  => $par['until'] ));
    }

    echo count($the_photos);
}

如果您仍然对此感到不舒服,那么只需关闭并使用offsetlimit,它们也可以作为参数使用。使用每个遍历的限制增加offset参数。