Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choose Non-default googlecalendar with google-java-client-api

I want to get all the Calendars, which are in my GoogleAccount, using the google java client API.

In my application I want that a user can choose in wich calendar his events will be saved (not only in the default). But therefore I need their CalendarIDs. I don't want that the users have to search their calendar ids to write them by hand into the app.

Would it be possible to create a new Calendar in his account, to write all the events in this new one.

Sorry for my bad English.

like image 614
R00st3r Avatar asked Mar 07 '12 07:03

R00st3r


1 Answers

Yes of course it is possible.You only have to know the calendarId in which you want to save the new event, and use them with the event insert function.

For example :

Event event = new Event();

event.setSummary("This is my Event");
event.setLocation("127.0.0.1 -- Home sweet Home!!");

ArrayList<EventAttendee> participants = new ArrayList<EventAttendee>();
participants .add(new EventAttendee().setEmail("[email protected]"));
event.setAttendees(participants);

DateTime start = new DateTime(new Date(), TimeZone.getTimeZone("UTC"));
event.setStart(new EventDateTime().setDateTime(start));

DateTime end = new DateTime(new Date(startDate.getTime() + 3600000), TimeZone.getTimeZone("UTC"));
event.setEnd(new EventDateTime().setDateTime(end));

Event createdEvent = service.events().insert("YourCalendarID", event).execute();

Hope this could help you!

like image 67
Kooki Avatar answered Nov 13 '22 15:11

Kooki