Should we add multiple events in google calendar using batch request?

Issue

I want to add multiple events in Google calendar using google calendar api with go lang. How can I achieve this? Is it correct to add multiple events simultaneously?

I am using the below mentioned pkg of golang to send request to google calendar.

    "google.golang.org/api/calendar/v3"

In for loop, I am maintaining the event data and send the request using:

 service.Events.Insert(calendarId, event).Do()

Would it be correct, if we I use go routine to send events?

Solution

To create an event, call the events.insert() method providing at least these parameters:

calendarId is the calendar identifier and can either be the email address of the calendar on which to create the event or a special keyword ‘primary’ which will use the primary calendar of the logged in user. If you don’t know the email address of the calendar you would like to use, you can check it either in the calendar’s settings of the Google Calendar web UI (in the section "Calendar Address") or you can look for it in the result of the calendarList.list() call.
event is the event to create with all the necessary details such as start and end. The only two required fields are the start and end times.

In order to successfully create events, you need to:

set your OAuth scope to https://www.googleapis.com/auth/calendar.
ensure the authenticated user has write access to the calendar with the calendarId you provided (for example by calling calendarList.get() for the calendarId and checking the accessRole).

calendarId := "primary"
event, err = srv.Events.Insert(calendarId, event).Do()
if err != nil {
  log.Fatalf("Unable to create event. %v\n", err)
}
fmt.Printf("Event created: %s\n", event.HtmlLink)

As per your question you are asking about adding multiple events using batch request.

Google calendar API only has the event adding one by one option in its option as far as I know.

You can also refer to this page for more details
https://developers.google.com/calendar/api/guides/create-events.

Answered By – S H A S H A N K

Answer Checked By – Willingham (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.