Events.create

From Facebook Developer Wiki

Jump to: navigation, search

Contents

Description

Creates an event on behalf of the user if the application has an active session key for that user; otherwise it creates an event on behalf of the application. Applications can create events for a user if the user grants the application the create_event extended permission.

If you are creating an event on behalf of a user, then your application is an admin for the event, while the user is the creator.

You can choose to upload an image to associate with the event. See photos.upload for details on supported formats. You can replace or delete images in an event using events.edit.

This method does not require a session key. However if you call this method without an active user session, then your application is both the creator and admin for the event.

Parameters

RequiredNameTypeDescription
required api_key string The application key associated with the calling application.
call_id float The request's sequence number. Each successive call for any session must use a sequence number greater than the last. We suggest using the current time in milliseconds, such as PHP's microtime(true) function.
sig string An MD5 hash of the current request and your secret key, as described in the How Facebook Authenticates Your Application.
v string This must be set to 1.0 to use this version of the API.
event_info object The event information, passed as a JSON-encoded object literal. See the Notes below for information on what parameters to include in the object.
optional session_key string The session key of the logged in user.
format string The desired response format, which can be either XML or JSON. (Default value is XML.)
callback string Name of a function to call. This is primarily to enable cross-domain JavaScript requests using the <script> tag, also known as JSONP, and works with both the XML and JSON formats. The function will be called with the response passed as the parameter.
[no name] data The raw image data of the picture to associate with the event.

Example Requests

Example Code in PHP

The $_POST[''] - Array have to be filed with the necessary variables so you can design a formular and send it via the method "POST" to a file that contains the following PHP-Code: Replace the XXXX... with your personal settings! <?php //declaration require_once 'facebook.php'; $appapikey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; $appsecret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; $facebook = new Facebook($appapikey, $appsecret); $user_id = $facebook->require_login(); if(!$facebook->api_client->users_hasAppPermission('create_event')){ echo'<script type="text/javascript">window.open("http://www.facebook.com/authorize.php?api_key='.$appapikey.'&v=1.0&ext_perm=create_event", "Permission");</script>'; echo'<meta http-equiv="refresh" content="0; URL=javascript:history.back();">'; exit; } $_POST['start_time']=mktime($_POST['start_time_hour'],$_POST['start_time_min'],"00",$_POST['start_time_month'],$_POST['start_time_day'],$_POST['start_time_hour']); $_POST['end_time']=mktime($_POST['end_time_hour'],$_POST['end_time_min'],"00",$_POST['end_time_month'],$_POST['end_time_day'],$_POST['end_time_hour']); unset($_POST['start_time_hour']); unset($_POST['start_time_min']); unset($_POST['start_time_month']); unset($_POST['start_time_day']); unset($_POST['start_time_hour']); unset($_POST['end_time_hour']); unset($_POST['end_time_min']); unset($_POST['end_time_month']); unset($_POST['end_time_day']); unset($_POST['end_time_hour']); try{ $event_id=$facebook->api_client->events_create(json_encode($_POST)); echo'<meta http-equiv="refresh" content="0; URL=">'; }catch(Exception $e){ echo 'Error message: '.$e->getMessage().' Error code:'.$e->getCode(); } ?> (hn)

Example Return XML

<?xml version="1.0" encoding="UTF-8"?> <events_create_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">34444349712 </events_create_response>

Error Codes

CodeDescription
1 An unknown error occurred. Please resubmit the request.
2 The service is not available at this time.
4 The application has reached the maximum number of requests allowed. More requests are allowed once the time window has completed.
5 The request came from a remote address not allowed by this application.
101 The API key submitted is not associated with any known application.
102 The session key was improperly submitted or has reached its timeout. Direct the user to log in again to obtain another key.
103 The submitted call_id was not greater than the previous call_id for this session.
104 Incorrect signature.

Notes

You must pass the following parameters in the event_info JSON object literal. The parameters are explained in Event (FQL).

Note: The start_time and end_time are the times that were input by the event creator, converted to UTC after assuming that they were in Pacific time (Daylight Savings or Standard, depending on the date of the event), then converted into Unix epoch time. Basically this means for some reason facebook does not want to get epoch timestamps here, but rather something like epoch timestamp minus 7 or 8 hours, depeding on the date. have fun!

Optionally, you can pass the following parameters in the event_info object:

  • street
  • phone
  • email
  • page_id
  • description
  • privacy_type
  • tagline

Note: The page_id argument can be used to (see e.g. browser line and find out the id or eid (11 numbers)):

  • generate events for groups
  • generate events for pages

Note: The privacy_type argument can be one of:

  • OPEN, for an event open and visible to everyone.
  • CLOSED, for an event that is visible to everyone but requires an invitation.
  • SECRET, for an event that is invisible to those who have not been invited.

So, a sample event_info object would look like this:

{"name":"name","category":"1","subcategory":"1","host":"host","location":"location","city":"Palo Alto, CA","start_time":1215929160,"end_time":1215929160}

See Also

reference