我想检索提要的所有事件并收集事件详细信息。像这样,我正在查询提要:
// instantiate
$facebook = new Facebook($config);
$pagefeed = $facebook->api("/" . $pageid . "/feed");
foreach($pagefeed['data'] as $post) {
// check if post type is a link
if ($post['type'] == 'event') {
// call API to retrieve the event details
}
}
正如您所看到的,我需要为每个事件发送一个请求。我可以像在oData中使用"展开"命令一样避免这种情况吗?
干杯
好吧,我自己想好了。到目前为止,我使用的方法已经过时了。当使用API 4x版本时,其工作原理如下:
// init app with app id and secret
FacebookSession::setDefaultApplication( FB_APP_ID, FB_SECRET);
// If you're making app-level requests:
$session = FacebookSession::newAppSession();
// To validate the session:
try {
$session->validate();
} catch (FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
} catch (Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
}
try {
$request = new FacebookRequest(
$session,
'GET',
// get all events of a Page, ?fields= let you choose which fields you want the Graph to return
'/' . FB_ID . '/events?fields=id,end_time,cover,description,is_date_only,location,name,start_time&since='
. strtotime('-1 year') . '&until=' . strtotime('+1 year')
. '&limit=10&locale=de_DE&date_format=d. M, y H:m'
);
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
// handle the result -> returns an indexed array without key
$objectData = $graphObject['data'];
很简单,如果你知道怎么做…;-)
希望这也能帮助其他人。