Google Calendar API v3的Python客户端库插入事件引发“缺少结束时间”错误

阿里·纳希德(Ali Nahid)

我在网上搜索了解决方案,但似乎我是唯一无法解决此问题的人。

这就是我的python代码:

class ReminderDate(object):
    def __init__(self, datetimestring, timezone="Australia/Sydney"):
        self.dateTime = datetimestring
        self.timeZone = timezone
class ReminderFormat(object):
    def __init__(self, useDefault=False):
        self.useDefault = useDefault
        self.overrides = [{"method":"email", "minutes":15}]
class ReminderData(object):
    def __init__(self, reminder, datefrom=None, dateto=None, datevalue=None):
        self.summary = reminder
        self.start = ReminderDate(datefrom)
        self.end = ReminderDate(dateto)
        self.reminders = ReminderFormat()

def save_event_to_google_calendar(self, reminder_data):
        credentials = self.get_credentials()
        service = build('calendar', 'v3', http=credentials.authorize(Http()))
        event = json.dumps(reminder_data, default=lambda o: o.__dict__)
        print (event)
        created_event = service.events().insert(calendarId=CALENDAR_ID, body=str(event), sendNotifications=True).execute()
        pp.pprint(created_event)

并且它产生因此print(event)输出一个json,如下所示:

{"start": {"timeZone": "Australia/Sydney", 
           "dateTime": "2015-04-26T18:45:00+10:00"}, 
 "end": {"timeZone": "Australia/Sydney", 
         "dateTime": "2015-04-26T19:00:00.000+10:00"}, 
 "reminders": {"overrides": [{"minutes": 15, "method": "email"}], 
               "useDefault": false}, 
 "summary": "do grocery shopping"}

我收到以下错误:

    File "/usr/local/lib/python2.7/dist-packages/googleapiclient/http.py", line 729, in execute
        raise HttpError(resp, content, uri=self.uri)
    googleapiclient.errors.HttpError: 
<HttpError 400 when requesting https://www.googleapis.com/calendar/v3/calendars/myemail%40gmail.com/events?alt=json&sendNotifications=true
 returned "Missing end time.">

我不明白。我在json中有“结束”时间。那我在这里想念什么?

我尝试通过Google开发人员控制台https://developers.google.com/google-apps/calendar/v3/reference/events/insert发布相同的json,并且它可以正常工作。但是它从python客户端库:((如上所述)中失败了


[编辑]找到解决方案

问题是我已经将Python对象转换为JSON“字符串”,而这正是我所提供的,而不是API期望的JSON“对象”。所以这是正确的代码:

json_event = json.loads(event)
created_event = service.events().insert(calendarId=CALENDAR_ID, body=json_event, sendNotifications=True).execute()
杰伊·李

尝试添加:

httplib2.debuglevel = 4

就在API调用之前。这将允许您查看events.insert()请求发送的确切正文。将其与API Explorer生成的主体进行比较,您应该得到答案。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Java客户端库从Google Calendar API v3查询事件?

来自分类Dev

Google Calendar API(红宝石)事件插入错误:缺少结束时间

来自分类Dev

在面向.NET 3.5的Winforms上使用Google Calendar API客户端库v3?

来自分类Dev

Google Calendar API插入事件

来自分类Dev

Google Calendar API插入事件

来自分类Dev

Google Calendar API V3授权

来自分类Dev

Google Calendar REST API错误

来自分类Dev

Google Calendar API位置python

来自分类Dev

Google Calendar API Python授权

来自分类Dev

使用Android的Google Calendar API插入事件

来自分类Dev

未经授权的Google Calendar API插入事件

来自分类Dev

使用Android的Google Calendar API插入事件

来自分类Dev

错误(401),需要登录-Google Calendar API v3

来自分类Dev

从Google Calendar API v2迁移到v3-客户端授权

来自分类Dev

HTTP GET:通过Google Calendar API v3获取Google Calendar事件列表-无效的密钥错误

来自分类Dev

如何在Google Calendar API的事件对象中设置开始时间和结束时间

来自分类Dev

Python事件集成中的QML Calendar和Google Calendar API

来自分类Dev

Google Calendar API缺少日历摘要

来自分类Dev

如何从Google Calendar API获取事件ID?

来自分类Dev

未创建Rails + Google Calendar API事件

来自分类Dev

如何使用Google Calendar API发布事件?

来自分类Dev

如何从Google Calendar API获取事件ID?

来自分类Dev

Google Calendar API日期和时间格式

来自分类Dev

如何修复Google Calendar API错误

来自分类Dev

设置Google Calendar API

来自分类Dev

带有Google Calendar API V3的Android Studio

来自分类Dev

How to Access Google Calendar REST API v3 with Java

来自分类Dev

Retrieve Google Calendar events using API v3 in javascript

来自分类Dev

使用PHP连接到Google Calendar v3 API

Related 相关文章

热门标签

归档