如何使用Python通过API v3创建Google日历事件

以下官方页面提供了有关如何使用
Python创建事件的示例.

https://developers.google.com/google-apps/calendar/v3/reference/events/insert#examples

他们给出的代码如下:

event = {
  'summary': 'Appointment',
  'location': 'Somewhere',
  'start': {
    'dateTime': '2011-06-03T10:00:00.000-07:00'
  },
  'end': {
   'dateTime': '2011-06-03T10:25:00.000-07:00'
  },
  'attendees': [
  {
    'email': 'attendeeEmail',
    # Other attendee's data...
  },
  # ...
  ],
}

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

print created_event['id']

但是,上面的示例并未说明如何建立连接并创建服务变量.由于我将日历设置为公开,因此我认为创建服务会非常容易.

任何人都知道如何建立连接?

最佳答案 我有一些困难,想知道如何使用OAuth等谷歌日历api.我终于得到了一切正常工作,一路上我写了一个非常简单易用的包.我把它发布到github,它可以使用“pip install gback”从pypi安装.该文档还包含有关Google帐户设置的说明.

https://github.com/Schwarzschild/gback

以下是用于向日历添加约会的示例snippit.

from gback import GCalSession

# print the output will display the appiointment url.
# 'Marc' is the name of the calendar used.

session = GCalSession('~/gback.oauth')
des='Write a simpler way to use the google calendar api.'
print session['Marc'].add('Write Python code.', '20150430', des=des)

享受,马克

点赞