关于this page Google 提供了以下示例,说明如何在 Google 日历中创建事件:
event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="315d41505654715449505c415d541f525e5c" rel="noreferrer noopener nofollow">[email protected]</a>'},
{'email': '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96e5f4e4fff8d6f3eef7fbe6faf3b8f5f9fb" rel="noreferrer noopener nofollow">[email protected]</a>'},
],
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
}
event = service.events().insert(calendarId='primary', body=event).execute()
print 'Event created: %s' % (event.get('htmlLink'))
这段代码工作正常,但我正在努力制作一个“全天”事件。我看到它建议,对于全天事件,传递的日期字符串应该缩写为日期,例如“2020-05-08”,但这样做会导致错误格式无效:“2020-05-08”太短”
。
最佳答案
我相信您的目标如下。
- 您想要使用 googleapis 和 python 创建全天事件。
- 您想了解
格式无效:“2020-05-08”太短”错误消息的原因
。
对于这个,这个答案怎么样?
修改点:
- 当
2020-05-08
用于dateTime
属性时,会出现此类错误。在这种情况下,请将其放入date
的属性中。
修改后的脚本:
当您的脚本修改时,请进行如下修改。
从:'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
到:
'start': {
'date': '2020-05-08',
'timeZone': 'America/Los_Angeles',
},
'end': {
'date': '2020-05-08',
'timeZone': 'America/Los_Angeles',
},
引用:
关于python-3.x - 如何使用 Google Calendar API 创建 "all-day"事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61643159/