Created
July 18, 2013 13:41
-
-
Save jboulhous/6029384 to your computer and use it in GitHub Desktop.
Create and Delete Facebook Events in a Meteor.js Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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