通过Facebook Graph API在已发布的帖子中获取Total Photo Count

时间:2017-07-07 07:24:35

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

我目前正试图通过Facebook Graph API在已发布的帖子中获取总照片数。我试过了

  

我/相册?字段=计数,名称

但这是在计算相册中的照片数量。提前致谢

For example, total photo count is four

1 个答案:

答案 0 :(得分:0)

 $count =0;
 $ALLalbums = $facebook->api('/me/albums?fields=id'); 
 $pics = array();
 foreach ($ALLalbums['data'] as $album) {
 $pics = $facebook->api('/'.$album['id'].'/photos?fields=source,picture');
 $pics[$album['id']] = $pics['data'];
}  
//Albums
foreach ($pics as $album) {
//Count Pics Inside each album
foreach ($album as $img) {
$count++;
// you can get image as well by $img['source'];
}
}
echo $count;