Skip to content

Instantly share code, notes, and snippets.

@tonibecker
Created October 5, 2012 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonibecker/3839229 to your computer and use it in GitHub Desktop.
Save tonibecker/3839229 to your computer and use it in GitHub Desktop.
Facebook Events with fql and datetimezone
<?php
require_once 'fb_api/facebook.php';
//this converts Pagename or Username to the specific ID
require_once 'convFbName.inc.php';
// make sure this api file is in your directory, if not get it here https://github.com/facebook/php-sdk/tree/master/src
//set the correct timezone more examples can be found at http://php.net/manual/en/timezones.php
date_default_timezone_set('Europe/Berlin');
// Authenticate
$facebook = new Facebook(array(
'appId' => '196555860474817',
'secret' => '925d3a7df5534746b92541aff1daa8d4',
'cookie' => true, // enable optional cookie support
));
// hunt down the fql query to get all needed data more can be found in the tables description
// in https://developers.facebook.com
try{
$fql = "SELECT eid, name, location, description, pic_big, start_time FROM event
WHERE creator = '$fbNameToId' AND eid IN
(SELECT eid FROM event_member WHERE uid = '$fbNameToId')
ORDER BY start_time asc LIMIT 5";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$events=$facebook->api($param);
}catch (FacebookApiException $e){
error_log($e);
}
// Iterate through each event
foreach ($events as $event){
// Get the start time of the event and convert it to a UNIX timestamp (hopefully)
// If the time falls within a day, show the event details. If the event is after today, show it as well.
// 60 (seconds/minute) * (60 minutes/hour) * 24 (hours/day) * 1 (day)
try{
// Fetch more details about the event
$start_time = date('M j, Y H:i ', strtotime($event['start_time']));
}catch (FacebookApiException $e){
// We errored :(
error_log($e);
}
// Show some HTMLsauce
?>
<li class="vevent">
<a href="#" data-lat="36.114646" data-long="-115.172816" title="" class="url">
<time class="dtstart" datetime="2011-12-14 21:00" title="2011-12-14 21:00"><?php echo $start_time; ?>
</time>
<h4 class="summary"><a href="http://www.facebook.com/event.php?eid=<?php echo $event['eid']; ?>"><?php echo $event['name']; ?></a></h4>
<b class="location"><?php echo $event["location"]; ?></b> </a>
</li>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment