0

我想获取朋友的照片总数,因为当我使用

$photos = $friend_id.'/photos';

我没有得到所有的照片。例如,如果一个朋友有 600 张照片,我只得到 180 左右或类似的数量,刷新页面后,我得到了更多照片,但没有得到所有照片。

所以我尝试使用

$photos = $friend_id.'/photos?limit=600';

并得到以下错误

Notice: Undefined index: data in *\friends-photos.php on line 107
0
Notice: Undefined index: data in *\friends-photos.php on line 115

Warning: Invalid argument supplied for foreach() in *\friends-photos.php on line 115

Notice: Undefined index: paging in *\friends-photos.php on line 132

错误行中的代码如下

 $var = $dp["data"] ; ------107  
 foreach ($dp["data"] as $value) ---------115 
 $next_page = $dp["paging"]["next"]; --------132
4

2 回答 2

0

根据https://developers.facebook.com/docs/reference/api/user/

用户 ID 的“照片”连接是“用户(或朋友)被标记的照片”。

在这种情况下,您会得到用户被标记的照片数量。而不是他相册中的照片总数。


https://developers.facebook.com/docs/reference/fql/photo/

“所有者”列不可索引。所以我们不能直接按所有者ID选择所有照片。

目前我还没有找到一种简单的方法来获取照片的总数。我可以做的是选择朋友的所有相册并遍历所有相册以获取每个相册中的照片数量。但是真的很慢......

于 2012-06-15T13:08:20.167 回答
0

您需要使用untilandlimit字段或limitandoffset字段

if($user_id) {
    $the_photos = array();
    $friend_id = '4'; // user id

    $friend_photos = $facebook->api($friend_id."/photos");

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

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

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

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

    echo count($the_photos);
}

我想想象一下,您在朋友个人资料上看到的照片编号包含对其具有某些隐私限制的照片,因此很可能与此处的编号不匹配。

有关更多信息,请参阅

于 2012-06-14T13:01:56.847 回答