所以我正在使用这个脚本来遍历给定页面中的事件.突然间我发现它不再起作用了:(
我觉得这可能是一个错误,因为如果您选择任何页面,使用access_token查看事件,则无法获取“下一个”分页URL的任何数据.例如在apigee.com上尝试https://graph.facebook.com/evenightclub/events
有任何想法吗?
($fid是页面对象id)
try { $facebook = new Facebook(array( 'appId' => '<removed>','secret' => '<removed>',)); $access_token = $facebook->getAccessToken(); $events_data = array(); $offset = 0; $limit = 5000; $params = array('access_token' => $access_token); //fetch events from Facebook API $data = $facebook->api("$fid/events/?limit=$limit&offset=$offset",$params); $events_data = array_merge($events_data,$data["data"]); //loop through pages to return all results while(in_array("paging",$data) && array_key_exists("next",$data["paging"])) { $offset += $limit; $data = $facebook->api("$fid/events/?limit=$limit&offset=$offset",$params); $events_data = array_merge($events_data,$data["data"]); }}
你的代码对我有用,我唯一做的就是确保count($data [“data”])>在将其与现有信息合并之前为0.所以它看起来像这样:
原文链接:https://www.f2er.com/php/134294.html//loop through pages to return all results while(in_array("paging",$data["paging"])) { $offset += $limit; $data = $facebook->api("$fid/events/?limit=$limit&offset=$offset",$params); // make sure we do not merge with an empty array if (count($data["data"]) > 0){ $events_data = array_merge($events_data,$data["data"]); } else { // if the data entry is empty,we have reached the end,exit the while loop break; } }}