
Facebook Events - can't be completely defined via the API
If you're developing Facebook applications using the AS3 API you'll eventually need to be able to create Facebook Events. That's where you'll need to be aware of another of Facebook's restrictions for application developers: You cannot completely define an Event and it's Invitees via the API.
Due to Facebook's antispam rules, you can create an Event with some basic information - name, location, timings, etc. Your application's user will then need to log into Facebook and complete the Event details and invite friends themselves. Great, I hear you say.
Well, being able to create the Event in the beginning and to automatically pass over information from your application to the new Event is going to be a big help to your application's users anyway.
So, how do you create the Event?
Firstly, you'll need to have established a valid Facebook session for your application and thereby have caused the user of your application to log into Facebook and grant your application access to their profile and information.
Here's a previous post with a working example and video tutorial link if you haven't gotten this far...
Then, you'll need to firstly create the Event data that is needed to set up the Event - of class CreateEventData:
Code:
| var eventData:CreateEventData = new CreateEventData(name, "OTHER", " ", host, locn, city, UTCstart, UTCend, null, null, null, 0, desc, privacy, null); |
OK, let's go through the above:
- name is clearly the name of the Event.
- host is usually the user who has created it.
- locn is the location of the event - this can be freeform, such as "my office".
- desc is a description for the event - not essential but it makes sense!
- city is going to have to be a valid town or city. If not, Facebook will try to guess what you meant and come up with the closest match - can be fun!
- UTCstart and UTCend are UTC versions of the start and end datetime values - both Date variables
Calculate values for these dates so:
Code:
| var UTCstart:Date = new Date(start.getUTCFullYear(), start.getUTCMonth(), start.getUTCDate(), start.getUTCHours(), start.getUTCMinutes(), start.getUTCSeconds(), start.getUTCMilliseconds()); |
- "OTHER" is the category for the Event. Facebook has numerous predefined categories and the one you use has to be valid.
- The " " empty String after "OTHER" is the sub-category.
See here for more about category and subcategory values...
I've found that " " works too for subcatgegories, should you not find a predefined one that fits your needs.
- The null values are those parameters which are not absolutely required to create an Event.
- privacy is an interesting one. When an Event is created in Facebook you have a choice of privacy settings - OPEN, CLOSED or SECRET. In my opinion there's not much point of specifying anything other than OPEN when creating an event via the API as there are no attendees at the point of creation anyway! Add to that the fact that only the user who created the Event will be able to see it and all is fine.
The user can then set the appropriate level once they have added attendees in Facebook.
Once you've created the CreateEventData you can call the API method to create the Event itself:
Code:
| var call:FacebookCall = fbook.post(new CreateEvent(eventData)); |
| call.addEventListener(FacebookEvent.COMPLETE, eventCreated); |
That's it!
in the eventCreated function you can detect the created Event's ID or dispatch events as needed. Don't forget to check that the call was successful as per this post.
For more information about the AS3 API CreateEventData class check the documentation here and the general Facebook API notes here.
One important note: If you don't want to waste hours of testing, wondering why this doesn't work, make sure that your application prompts the user to grant it extended "create event" permissions when they first use it. the easiest way to do this is to specify the following in the "Post-Authorize Redirect URL" of your applications settings in Facebook:
www. facebook.com/authorize.php?api_key=<your application key here>&v=1.0&ext_perm=create_event
As soon as they've given their approval for your application to create events, nothing else should prevent it. Just remember they can always change their minds!
Happy coding!
Recent comments