How can I get all events created by an Facebook application?
How can I get all event开发者_运维知识库s created by a Facebook application using the Graph API? I tried doing
$appevents = $facebook->api('/**applicationid**/events',
'get', array("fields"=>"id, name, start_time, updated_time"));
but it did not work.
- Download Facebooks PHP SDK
- Add YOUR_APP_ID
- Add YOUR_APP_SECRET
- Add PAGE_ID
- Make changes to the FQL statement as you see fit. FQL Documentation
Other than that you should be good to go. Also, I set the default timezone to America/Los_Angeles. This will probably cause problems later, if anyone has a better way to handle it please let me know.
PHP Code:
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;
}
精彩评论