I\'m trying to use Google calendar REST API within Meteor I can use any GET method without any problem, but when I try to create an event in a calendar I get an Unauthorized
After quite a good while of trying got it right..
Added the following file to my client folder
Accounts.ui.config({requestPermissions: {google:
['https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/tasks']}}, requestOfflineToken: {google: true})
gCal =
insertEvent: (cliente, poblacion, texto, fecha)->
#to-do calendar devuelve un Event Object que incluye un ID
# si incluimos este id como campo en la alerta podremos despues
# eliminar el evento en el calendario directamente desde la app
url = "https://www.googleapis.com/calendar/v3/calendars/primary/events"
event= {
summary: cliente
location: poblacion
description: texto
start:
"date": fecha
end:
"date": fecha
}
evento = JSON.stringify event
console.log evento
Auth = 'Bearer ' + Meteor.user().services.google.accessToken
Meteor.http.post url, {
params: {key: 'INSERT-YOUR-API-KEY-HERE'},
data: event,
headers: {'Authorization': Auth }
},
(err, result)->
console.log result
return result.id
if you logged in thru {{loginButtons}} and then call insertEvent it works like a charm.