Reputation: 6865
I have a Google App Engine Service set up and running on a Google account A. What I would like to be able to do is book events on my business's Google Calendar account B. I followed this as a general guide. Here are the steps I have done to do this (Note: the AppEngine is already running and functional.
https://www.googleapis.com/auth/calendar
to the id of my service for my App Engine in account A.Note: in the getCalendarService
, I'm getting the credentials using ADC following this repo's README
func getCalendarService() (*calendar.Service, error) {
ctx := context.Background()
return calendar.NewService(ctx, option.WithScopes(calendar.CalendarScope))
}
// code adapted from https://developers.google.com/calendar/create-events/
func bookEvent() {
srv, err := getCalendarService()
if err != nil {logAndPrintError(err)}
event := &calendar.Event{
Summary: "Test Title",
Description: "Lorem ipsum",
Start: &calendar.EventDateTime{
DateTime: "2020-02-12T09:00:00-07:00",
TimeZone: "America/Chicago",
},
End: &calendar.EventDateTime{
DateTime: "2020-02-12T17:00:00-07:00",
TimeZone: "America/Chicago",
},
}
calendarId := "primary"
event, err = srv.Events.Insert(calendarId, event).Do()
if err != nil {
logAndPrintError(err)
}
log.Printf("Event created: %s\n", event.HtmlLink)
}
When I look in log and error reporting there is no error, and the logs show this message:
Event created: a Calendar URL
but when I copy the link and go to my Google Account B and load it, Google Calendar says "Could not find the requested event". It is worth mentioning that if I load the url into Account A, it says the same thing.
For some reason there is no error, but the event does not work. I don't think it is a problem in my code but a problem in the credentials, but I could be wrong.
Note: I'm not downloading any keys, I'm using ADC with App Engine to get my credentials.
Upvotes: 0
Views: 276
Reputation: 26796
If I am not mistaken,
you creating a calendar event with a Service account and insert this event into the primary calendar OF THE SERVICE ACCOUNT
This is probably not what you wanted,instead, if you want to insert the event into your primary calendar either
calendarId
instead of primary - this implies that your share your calendar with the service account beforehandServiceAccountUser
Upvotes: 1