如何使用Graph API获取Facebook应用程序创建的所有活动?我试着做了
$appevents = $facebook->api('/**applicationid**/events',
'get', array("fields"=>"id, name, start_time, updated_time"));
但它不起作用。
答案 0 :(得分:1)
除此之外你应该好好去。另外,我将默认时区设置为America / Los_Angeles。这可能会在以后出现问题,如果有人有更好的方法来处理它,请告诉我。
PHP代码:
date_default_timezone_set('America/Los_Angeles');
function display_events()
{
$app_id = 'YOUR_APP_ID';
$secret = 'YOUR_APP_SECRET';
$page_id = 'PAGE_ID';
$config = array();
$config['appId'] = $app_id;
$config['secret'] = $secret;
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
$fql = 'SELECT
eid,
name,
pic_square,
creator,
start_time,
end_time
FROM event
WHERE eid IN
(SELECT eid
FROM event_member
WHERE uid='.$page_id.'
)
AND end_time >= ' . mktime() . '
ORDER BY start_time ASC
';
$ret_obj = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
$html = '';
foreach($ret_obj as $key)
{
$facebook_url = 'https://www.facebook.com/event.php?eid=' . $key['eid'];
$start_time = date('M j, Y \a\t g:i A', $key['start_time']);
$end_time = date('M j, Y \a\t g:i A', $key['end_time']);
$html .= '
<div class="event">
<a href="'.$facebook_url.'">
<img src="'.$key['pic_square'].'" />
</a>
<span>
<a href="'.$facebook_url.'">
<h2>'.$key['name'].'</h2>
</a>
<p class="time">'.$start_time.'</p>
<p class="time">'.$end_time.'</p>
</span>
</div>
';
}
echo $html;
}