2013-01-09 133 views
0

我正在尝试在流星内使用Google日历REST API我可以使用任何GET方法而没有任何问题,但是当我尝试在日历中创建事件时,我收到未经授权的访问错误。未经授权访问Google Calendar API发布请求

我得到了我以下要点code

Basicaly代码我使用Meteor.loginWithGoogle,并得到一个的accessToken,有了它我可以从谷歌的任何日历或用户信息,但是当我尝试插入一个事件,我得到以下消息:

POST https://www.googleapis.com/calendar/v3/calendars/primary/events 401(未授权)

什么想法?

+0

嘿,呃,请接受你的问题更多的答案。在这里接受答案被认为是礼貌的,它有助于增加你在将来得到好答案的机会。 – Rahul

+2

我很乐意接受问题的答案,不仅它很有礼貌,而且也是我认为该网站的目标,但我觉得这是一个很好的答案,不完全解决问题对任何人都没有好处谁会寻找类似的问题。我回顾了我的所有问题(不是很多),并检查了一个很好的答案。谢谢你的评论 :) – Perseoh

回答

6

后试图相当不错的,而这样做是正确..

添加下列文件到我的客户端文件夹

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 

,如果你登录直通{{loginButtons}},然后调用insertEvent它奇迹般有效。