【问题标题】:creating event gives 400 bad request - Google calendar API using AUTHLIB (Python package)创建事件会给出 400 个错误请求 - 使用 AUTHLIB(Python 包)的 Google 日历 API
【发布时间】:2022-01-30 17:23:00
【问题描述】:

这是我创建事件的请求(使用 PyPi 的 AuthLib)

resp = google.post(
    'https://www.googleapis.com/calendar/v3/calendars/primary/events', data={
        'start': {'dateTime': today.strftime("%Y-%m-%dT%H:%M:%S+05:30"), 'timeZone': 'Asia/Kolkata'},
        'end': {'dateTime': tomorrow.strftime("%Y-%m-%dT%H:%M:%S+05:30"), 'timeZone': 'Asia/Kolkata'},
        'reminders': {'useDefault': True},
    }, token=dict(session).get('token'))

我得到的响应

{"error":{"code":400,"errors":[{"domain":"global","message":"Bad Request","reason":"badRequest"}],"message":"Bad Request"}}

注意事项:

  1. 我已经使用相同的库和方法完成了 get 请求和工作
  2. 包括范围(如文档中所述)

另请注意:

我已经浏览了有关此特定错误请求和 api 端点的所有现有 stackoverflow 答案,其中大多数人的时间格式存在问题,我已经尝试过所有这些问题,现在我坚持使用 google api docs 时间格式。

【问题讨论】:

  • @khelwood *关于这个特定的错误请求和api端点我支持它:)

标签: python google-calendar-api authlib


【解决方案1】:

你可以试试gcsa库(documentation)。它为您处理时间格式:

from gcsa.google_calendar import GoogleCalendar
from gcsa.event import Event

event = Event(
    'My event',
    start=today,
    end=tomorrow,
    timezone='Asia/Kolkata'
)
calendar.add_event(event)

安装它

pip install gcsa

【讨论】:

  • 这太棒了!但是 authlib 是一个通用的 OAuth 处理库,所以我很想坚持使用这个库
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-08
  • 2021-09-25
相关资源
最近更新 更多