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

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

问题描述

我试图在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,通过它我可以从Google获取任何日历或userInfo,但是当我尝试插入事件时,我会收到以下消息:

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发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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