Skip to content

Instantly share code, notes, and snippets.

@jboulhous
Created July 18, 2013 13:41
Show Gist options
  • Save jboulhous/6029384 to your computer and use it in GitHub Desktop.
Save jboulhous/6029384 to your computer and use it in GitHub Desktop.
Create and Delete Facebook Events in a Meteor.js Application
if (Meteor.isClient){
function throwError (param) {
throw new Error('Need a '+ param + 'for the event to be created')
}
createEvent = function(options,cb){
var name = options && options.name || throwError('name');
var start = options && options.start_time || throwError('start_time');
var access_token = options && options.access_token || throwError('access_token');
var url = "https://graph.facebook.com/1157277290/events?";
var params = {
name : name,
start_time : start,
access_token : access_token
};
var _cb = cb || function(){};
var callback = function(error,eventId){
if (error){
Meteor._debug('Error',error.response.data.error);
_cb(error,null)
} else {
Meteor._debug("Event created with ID : ",eventId);
_cb(null,eventId)
}
};
url += $.param(params,{},callback);
return Meteor.http.post(url,{},callback);
}
deleteEvent = function(id){
var url = 'https://graph.facebook.com/' + id + '?';
url += $.param({
access_token : Meteor.user().services.facebook.accessToken
})
return Meteor.http.del(url,{},function(e,r){
if(e)
Meteor._debug('error deleting event')
else
Meteor._debug('Event deleted')
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment