Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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".

like image 630
Mick Avatar asked Nov 05 '25 05:11

Mick


1 Answers

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:

  • Request body of Events: insert
like image 192
Tanaike Avatar answered Nov 07 '25 09:11

Tanaike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!