未经授权访问 Google Calendar API post 请求 [英] Unauthorized access to Google Calendar API post request

查看:29
本文介绍了未经授权访问 Google Calendar API post 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 access error.

我在以下要点上得到了我的代码代码

I got my code on the following gist code

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

Basicaly I use Meteor.loginWithGoogle and get an AccessToken, with it I can get any calendar or userInfo from google, but when I try to insert an event I get the following message:

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

POST https://www.googleapis.com/calendar/v3/calendars/primary/events 401 (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

如果您通过 {{loginButtons}} 登录然后调用 insertEvent 它就像一个魅力.

if you logged in thru {{loginButtons}} and then call insertEvent it works like a charm.

这篇关于未经授权访问 Google Calendar API post 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆