Mick
Mick

Reputation: 7937

How to create "all-day" events with Google Calendar API

On this page Google give the following example of how to create an event in a Google calendar:

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': '[email protected]'},
    {'email': '[email protected]'},
  ],
  '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'))

This code works fine, but I am struggling to make an "all-day" event. I have seen it suggested that with an all day event the date string passed should be abbreviated to being just the date, e.g. "2020-05-08" but doing this results in an error Invalid format: "2020-05-08" is too short".

Upvotes: 2

Views: 2902

Answers (1)

Tanaike
Tanaike

Reputation: 201378

I believe your goal as follows.

  • You want to create an all-day event using googleapis with python.
  • You want to know the reason of the error message of Invalid format: "2020-05-08" is too short".

For this, how about this answer?

Modification point:

  • When 2020-05-08 is used to the property of dateTime, such error occurs. In this case, please put it to the property of date.

Modified script:

When your script is modified, please modify as follows.

From:
'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',
},
To:
'start': {
  'date': '2020-05-08',
  'timeZone': 'America/Los_Angeles',
},
'end': {
  'date': '2020-05-08',
  'timeZone': 'America/Los_Angeles',
},

Reference:

Upvotes: 5

Related Questions