How to delete an event from Facebook using Graph API

Facebook provides a set of API for managing events.

https://developers.facebook.com/docs/reference/api/event/

In order to be able to delete an event, you must have an access token with permission

“create event”. (There is no permission specifically for deleting an event)

Essentially, the way you delete it is sending a DELETE request to the event object using the object id. We can start out by trying the DELETE command in the GraphAPI explorer. First, get the “create_event” (in extended permission) access token using GetAccessToken button. Then, Select DELETE on the left, and type in /eventID, and you should see a success message.

To replicate what you did in code, I used

</pre>
[FBRequestConnection startWithGraphPath:eventID
    parameters:nil
    HTTPMethod:@"DELETE"
    completionHandler:
       ^(FBRequestConnection *connection, id result, NSError *error) {
   if (error) {
     NSLog(@"Error: %@", result);
   } else {
 NSLog(@"Success: %@", result);
}
}];
<pre>

A few Notes:

  1. Make sure that you have an open session if order for the request to be successful. Other wise, there would be an error and the result would be null. 
  2. You could actually achieve the same effect using a POST command(In case there is no DELETE command available), but with an additional parameter method=delete. I have tested this on Graph API explorer and it works. It is documented here https://developers.facebook.com/docs/reference/api/#deleting
  3. Several APIs listed in FBRequestConnection seem to be missing. There was one called “startForDeleteObject” documented here, https://developers.facebook.com/docs/reference/ios/3.0/class/FBRequestConnection/, but it is nowhere to be found. It seems that everything is converged to “startWithGraphPath: Parameters: CompletionHandler” method.
Advertisements
This entry was posted in Facebook API. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s