2

I am trying to insert an event into a google calendar via the java API: CalendarTest

I would like to run:

new Calendar.Events.Insert(calendarId, content).execute();

except that the constructor is protected and I cannot find a static public method to do the insert. Any suggestions?

Kara
  • 6,115
  • 16
  • 50
  • 57
Jason Posit
  • 1,323
  • 1
  • 16
  • 36

2 Answers2

1

I solved this issue as follows:

calendarClient.events().insert(appCalendarId, calendarEvent).execute();
Jason Posit
  • 1,323
  • 1
  • 16
  • 36
0

Yes by creating object of google's Event class's type and then calling various methods for adding event to calendar :-

Event event = new Event();
event.setStart(new EventDateTime().setDateTime(start));
event.setEnd(new EventDateTime().setDateTime(end));
event.setSummary(eventEntity.getSummary());
event.setLocation(location);
event.setDescription(description);

after that calling following code to insert the event

calendarService.events().insert(appCalendarId, calendarEvent).execute();

here the calendarService is generated from google's credentials that we get after successful response from google api

kakabali
  • 3,824
  • 2
  • 29
  • 58
  • To insert an event you need 'calendarId' i.e. a Calendar identifier. To retrieve calendar IDs call the calendarList.list method. If you want to access the primary calendar of the currently logged in user, use the "primary" keyword. `calendarService.events.insert("primary", newEvent).execute()` – kosiara - Bartosz Kosarzycki Apr 09 '18 at 07:51
  • yes correct, "primary" is the default calendar so specifying it is like going to create event that way – kakabali Apr 09 '18 at 11:05
  • Can I ask where "calendarService"? What request generated it? – blah Nov 22 '22 at 06:30