gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:03:03 25 4
gpt4 key购买 nike

以下官方页面给出了如何使用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']

但是,上面的示例并没有说明如何建立连接和创建 service 变量。由于我已将日历设置为公开,因此我认为创建 service 会容易得多。

有人知道如何建立连接吗?

最佳答案

我在弄清楚如何将 google calendar api 与 OAuth 等一起使用时遇到了一些困难。我终于让一切正常工作,并且在这个过程中我编写了一个非常简单易用的包。我将它发布到 github,它可以使用“pip install gback”从 pypi 安装。该文档还包含有关 google 帐户设置的说明。

https://github.com/Schwarzschild/gback

这是一个将约会添加到日历的示例代码段。

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)

好好享受吧,马克

关于python - 如何使用 Python 通过 API v3 创建 Google 日历事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27436551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com