所以我正在使用这个脚本来遍历给定页面中的事件.突然间我发现它不再起作用了:(
我觉得这可能是一个错误,因为如果您选择任何页面,使用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.所以它看起来像这样:
//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; } }}
原文地址:https://www.jb51.cc/php/134294.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。