The new Facebook API adds additional method calls that give Facebook Applications additional functionality. One such functionality is the ability to create events using the new events.create method. Although this functionality has been added to the API the supplied php5 library file does not include a function to call this method nor does the facebook wiki page on events.create make it clear how exactly to use this method. This article will show you exactly how to use events.create as there are some special requirements for this method.
Add events_create function to facebookapi_php5_restlib.php
public function &events_create($event_info) {
return $this->call_method('facebook.events.create',
array(
'event_info' => json_encode($event_info),
'format' => 'XML'));
}
name - string category - int subcategory - int location - string city - string - Must be a valid city name or else the method will throw an error start_time - utc time - look at example below on how to convert a time to UTC end_time - utc timeOptional parameters of $event_info
street - string phone - string email - string page_id - int host - string desc - string privacy_type - int tagline - stringUsing events_create
include_once 'client/facebook.php';
include_once 'config.php';
$facebook = new Facebook($api_key, $secret);
$user = $facebook->require_login();
$fapi = $facebook->api_client;
//Setup array with paramets you would like to pass into events.create
$event_info = array();
$event_info['name'] = 'Party';
$event_info['category'] = 1;
$event_info['subcategory'] = 1;
$event_info['host'] = 'You';
$event_info['location'] = 'Your House';
$event_info['city'] = 'Toronto'; //Must be a valid city name
$event_info['start_time'] = gmmktime(22,0,0,9,3,2008); //Converts time to UTC
$event_info['end_time'] = gmmktime(5,0,0,9,5,2008); //COnverts time to UTC
//Call events_create
//Display events id on event creation
//Display error message with error code on error
try
{
$event_id = $fapi->events_create($event_info);
echo 'Event Created! Event Id is: '.$event_id;
}
catch(Exception $e)
{
echo 'Error message: '.$e->getMessage().' Error code:'.$e->getCode();
}
And there you have it, a simple yet effective way to using the new events.create method call in the Facebook API.