2

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

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

1 回答 1

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);
}

如果您仍然对此感到不舒服,那么只需切换并使用offsetand limit,它们也被允许作为参数。offset使用每次遍历的限制增加参数。

于 2012-07-10T03:28:29.120 回答