python-3.x - 如何使用 Google Calendar API 创建 "all-day"事件

标签 python-3.x google-calendar-api

关于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/

相关文章:

python - 比循环和调用循环调用另一个函数的函数更好的方法

python - mylist.count(mylist) 能否返回非零值?

python - 使用另一个dict python在嵌套Json中插入元素

jquery - 使用 JQuery 解析 Google Calendar v3 API JSON

python - 与 Python 2 相比,Python 3 上的 Tensorflow 更慢

python-3.x - 需要找到完全匹配并使用正则表达式替换

c# - Google AuthenticatorFactory 替代品?

javascript - googleapis TypeError : authClient. 请求不是 nodejs 中的函数

javascript - 验证 Google 日历网站/将其列入白名单

java - 如何将分钟添加到 EventdateTime 并转换为 DateTime