Facebook:在like和comment数组中为foreach()提供的参数无效

时间:2012-03-04 20:14:32

标签: php facebook facebook-graph-api

我正在尝试从facebook中检索。以下代码检索所有ID。但是我收到错误为foreach()提供的无效参数为行 foreach($ status ['喜欢''['data']为$ likesData)

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

foreach($statuses['data'] as $status){

   foreach($status['likes']['data'] as $likesData){

   $frid=$likesData['id']; 
   echo  $frid;
   echo  "<br>";
   }
   }

1 个答案:

答案 0 :(得分:0)

并非所有状态都喜欢(就像并非所有状态都有评论一样)所以您需要首先检查状态是否喜欢:

$statuses = $facebook->api('/me/statuses');
foreach($statuses['data'] as $status){
    if(!empty($status['likes'])) {
        foreach($status['likes']['data'] as $likesData){
            $frid=$likesData['id']; 
            echo  $frid;
            echo  "<br>";
        }
    }
}

显然你需要先检查一下你是否有任何状态!