【问题标题】:Unauthorized access to Google Calendar API post request未经授权访问 Google Calendar API 发布请求
【发布时间】:2012-12-23 00:40:40
【问题描述】:

我正在尝试在 Meteor 中使用 Google 日历 REST API,我可以毫无问题地使用任何 GET 方法,但是当我尝试在日历中创建事件时,我收到未经授权的访问错误。

我的代码在以下要点 code

基本上我使用 Meteor.loginWithGoogle 并获得一个 AccessToken,通过它我可以从谷歌获得任何日历或用户信息,但是当我尝试插入一个事件时,我收到以下消息:

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

有什么想法吗?

【问题讨论】:

  • 嗨 Persech,请接受对您问题的更多回答。在这里接受答案被认为是有礼貌的,这有助于增加您将来获得好答案的机会。
  • 我很乐意接受这些问题的答案,这不仅是礼貌的,也是我认为该网站的用途,但我觉得将一个不能完全解决的答案标记为好这个问题对寻找类似问题的任何人都没有好处。我检查了我所有的问题(不是很多)并检查了一个很好的答案。感谢您的评论:)

标签: meteor


【解决方案1】:

经过一段时间的尝试,它是正确的..

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

 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,它就像一个魅力。

【讨论】:

    猜你喜欢
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-22
    • 2017-07-06
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多