I know this question was asked years ago but I struggled for several hours today with this exact response from Google calendar for an event insert and after finding out the problem I thought I'd record it for posterity.
On https://agendarizer.com we allow people to connect to a Google calendar to synchronize meeting agendas. We have this scope setup in the OAuth consent screen:
https://www.googleapis.com/auth/calendar.events
...which the docs say should be sufficient. With this code we were constantly getting a 403 Forbidden, exactly as shown above:
val event = new Event()
val url = getAgendaUrl(agenda)
event.setSummary(agenda.title)
event.setDescription("Agenda: " + url)
event.setStart(getInstantAsDateTime(date, creator.getTimeZone))
event.setEndTimeUnspecified(true)
service.events().insert(calendar.getId, event).execute()
It turns out that setting an unspecified end time was the cause of the error. Altering the code to specify an end time got things working:
val event = new Event()
val url = getAgendaUrl(agenda)
event.setSummary(agenda.title)
event.setDescription("Agenda: " + url)
event.setStart(getInstantAsDateTime(date, creator.getTimeZone))
event.setEnd(getInstantAsDateTime(date.plus(1, ChronoUnit.HOURS), creator.getTimeZone))
service.events().insert(calendar.getId, event).execute()
(getInstantAsDateTime
is a helper method that converts a java.time.Instant
into a Google EventDateTime
).