Facebook Graph API的多个页面ID

时间:2015-03-06 11:45:40

标签: php facebook facebook-graph-api

我在这里遇到这个php问题,我无法找到解决方案。

现在,下面的代码显示来自某个特定Facebook页面的所有事件 $ fb_page_id:" 357734517342&#34 ;;

我的问题是,如果我想从多个Facebook页面ID中显示,我应该如何制作?

PS:我试过在json中添加/?ids = page1id,page2id /但是它没有用。

我有以下代码:

session_start();
$fb_page_id = preg_replace( '/[^0-9]/', '', isset($_GET['fb_page_id']) ? $_GET['fb_page_id'] : "");
$fb_page_id = !empty($fb_page_id) ? $fb_page_id : "357734517342";

$access_token="<MY ACCESS TOKEN>";

$fields="id, name, description, location, venue, timezone, start_time, cover";
$limit=5;
$year_range = 1;

if($show=="all"){
    // automatically adjust date range
    // human readable years
    $since_date = date('Y-01-01', strtotime('-' . $year_range . ' years'));
    $until_date = date('Y-12-31', strtotime('+' . $year_range . ' years'));
}

// json link
$json_link = "https://graph.facebook.com/{$fb_page_id}/events/attending/?fields={$fields}&access_token={$access_token}&since={$since_unix_timestamp}&until={$until_unix_timestamp}&limit={$limit}";

$json = file_get_contents($json_link);
$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

$next_page = isset($obj['paging']['next']) ? $obj['paging']['next'] : "";
$_SESSION['EVENTS_NEXT_PAGE_' . $fb_page_id]=$next_page;
$_SESSION['EVENTS_SET_NUM_' . $fb_page_id]=1;

1 个答案:

答案 0 :(得分:0)

我认为您应该以这种方式将逗号分隔的ID作为GET变量之一:

$json_link = "https://graph.facebook.com/events/attending/?ids=PAGE1_ID,PAGE2_ID&fields={$fields}&access_token={$access_token}&since={$since_unix_timestamp}&until={$until_unix_timestamp}&limit={$limit}";