【问题标题】:Missing endtime whie inserting to calendar event插入日历事件时缺少结束时间
【发布时间】:2021-03-20 10:22:38
【问题描述】:

在尝试插入和事件时,尽管我尝试使用不同的时区,甚至复制粘贴了 sn-p 提供的代码 Events:insert,但我不断收到相同的错误。 我得到的错误是:
<HttpError 400 when requesting https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json returned "Missing end time.". Details: "Missing end time.">

我用来创建事件的代码是:

    event = {
        'summary': data['summary'],
        'description': data['description'],
        'start': {
            'dateTime': data['start_time'],
            'timeZone': 'ASIA/KOLKATA',
        },
        'end': {
            'dateTime': data['end_time'],
            'timeZone': 'ASIA/KOLKATA',
        },
        'recurrence': [
            'RRULE:FREQ=DAILY;COUNT=2'
        ],
        'attendees': [
            {'email': 'moinkhan8439@gmail.com'},
            {'email': 'zainkhanjune@gmail.com'},
            ],
        'reminders': {
            'useDefault': False,
            'overrides': [
            {'method': 'email', 'minutes': 24 * 60},
            {'method': 'popup', 'minutes': 10},
            ],
        }
    }
created_event = service.events().insert(calendarId='primary', body=event).execute()

我尝试转换为 RFC3339 但同样的错误。
注意 - 我通过序列化程序从 POST 请求中获取数据。

【问题讨论】:

    标签: google-calendar-api google-api-python-client


    【解决方案1】:

    当我们没有在插入函数的正文部分传递正确的格式时会发生此错误。

    service.events().insert(calendarId='primary',sendNotifications=True, body=event).execute()

    我发现我正在将 datetime 对象传递给事件的 datetime 关键字,而我们必须首先将 datetime 转换为标准 RFC339,如授权部分 here 中指定的那样 然后将其转换为字符串传递给事件体。

    要将 Django models.datetime 对象转换为 RFC3339 字符串,请执行以下操作:

    str(date.isoformat('T'))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 2016-10-31
      • 1970-01-01
      • 2015-07-03
      相关资源
      最近更新 更多