public static List<GEvent> DownloadEvents(DateTime from, DateTime to) { com.google.api.services.calendar.Calendar mService = GoogleProvider.getInstance().GetServiceCalendar(); List<GCalendar> calendars = CalendarListAsyncTask.DownloadCalendars(); ; Log.d("asyncEvents", "doInBackground - 2"); Log.d("asyncEvents", "doInBackground - calendars count " + calendars.size()); List<GEvent> eventList = new ArrayList<>(); for (GCalendar calEntry : calendars) { try { Events events = mService .events() .list(calEntry.id) .setMaxResults(10) .setTimeMin(from) .setTimeMax(to) .setOrderBy("startTime") .setSingleEvents(true) .execute(); List<Event> items = events.getItems(); for (Event event : items) { eventList.add(newGEvent(event, calEntry)); } } catch (IOException e) { } } return eventList; }
private void loadCalendarEvents( final Calendar calendar, final CalendarListEntry calendarEntry, final UpdateInfo updateInfo, final Long since) throws IOException { String pageToken = null; do { long then = System.currentTimeMillis(); final Calendar.Events.List eventsApiCall = calendar.events().list(calendarEntry.getId()); final String uriTemplate = eventsApiCall.getUriTemplate(); try { eventsApiCall.setPageToken(pageToken); eventsApiCall.setShowHiddenInvitations(true); eventsApiCall.setSingleEvents(true); eventsApiCall.setTimeMax(new DateTime(System.currentTimeMillis())); if (since != null) eventsApiCall.setTimeMin(new DateTime(since)); final Events events = eventsApiCall.execute(); countSuccessfulApiCall(updateInfo.apiKey, updateInfo.objectTypes, then, uriTemplate); final List<Event> eventList = events.getItems(); storeEvents(updateInfo, calendarEntry, eventList); pageToken = events.getNextPageToken(); } catch (Throwable e) { countFailedApiCall( updateInfo.apiKey, updateInfo.objectTypes, then, uriTemplate, ExceptionUtils.getStackTrace(e), eventsApiCall.getLastStatusCode(), eventsApiCall.getLastStatusMessage()); throw (new RuntimeException(e)); } } while (pageToken != null); }
private void updateCalendarEvents( final Calendar calendar, final CalendarListEntry calendarEntry, final UpdateInfo updateInfo, long since) throws IOException { // In the unlikely case where the server was down or disconnected more than 20 days and thus // wasn't able to // check for updated items during this period, we need to constrain the updatedMin parameter to // a maximum // of 20 days in the past, at the risk of getting an error from Google since = Math.max(since, System.currentTimeMillis() - 20 * DateTimeConstants.MILLIS_PER_DAY); String pageToken = null; do { long then = System.currentTimeMillis(); final Calendar.Events.List eventsApiCall = calendar.events().list(calendarEntry.getId()); final String uriTemplate = eventsApiCall.getUriTemplate(); try { eventsApiCall.setPageToken(pageToken); eventsApiCall.setShowHiddenInvitations(true); eventsApiCall.setSingleEvents(true); eventsApiCall.setTimeMax(new DateTime(System.currentTimeMillis())); eventsApiCall.setUpdatedMin(new DateTime(since)); final Events events = eventsApiCall.execute(); countSuccessfulApiCall(updateInfo.apiKey, updateInfo.objectTypes, then, uriTemplate); final List<Event> eventList = events.getItems(); storeEvents(updateInfo, calendarEntry, eventList); pageToken = events.getNextPageToken(); } catch (Throwable e) { logger.warn( "updateCalendarEvents unexpected httpCode=" + eventsApiCall.getLastStatusCode() + " reason=" + eventsApiCall.getLastStatusMessage() + " since=" + since + " message=" + e.getMessage()); countFailedApiCall( updateInfo.apiKey, updateInfo.objectTypes, then, uriTemplate, ExceptionUtils.getStackTrace(e), eventsApiCall.getLastStatusCode(), eventsApiCall.getLastStatusMessage()); throw (new RuntimeException(e)); } } while (pageToken != null); }
public void listAllEvents() throws IOException, ParseException { List<String[]> myList = new ArrayList<String[]>(); eventsList = new ArrayList<Object[]>(); com.google.api.services.calendar.Calendar service = getCalendarService(); // List the next 10 events from the primary calendar. DateTime now = new DateTime(System.currentTimeMillis()); Events events = service .events() .list("primary") .setMaxResults(20) .setTimeMin(now) .setOrderBy("startTime") .setSingleEvents(true) .execute(); List<Event> items = events.getItems(); for (Event e : items) { System.out.println(e.getSummary() + " , " + e.getStart()); } if (items.size() == 0) { System.out.println("No upcoming events found."); } else { System.out.println("Upcoming events"); for (Event event : items) { DateTime start = event.getStart().getDateTime(); if (start == null) { start = event.getStart().getDate(); } String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); String startString = new SimpleDateFormat("MM/dd/yyyy") .format( new SimpleDateFormat("yyyy-MM-dd").parse(start.toString().substring(0, 10))); Object[] eventArray = new Object[2]; eventArray[0] = event.getSummary(); eventArray[1] = start.toString().equals(today) ? "Today" : startString; eventsList.add(eventArray); } } }
public void createCalEvent(Date startDate, Date endDate, String summary, String desc) throws IOException { com.google.api.services.calendar.Calendar service = getCalendarService(); Event createEvent = new Event().setSummary(summary).setDescription(desc); DateTime startTime = new DateTime(startDate); DateTime endTime = new DateTime(endDate); EventDateTime start = new EventDateTime().setDateTime(startTime).setTimeZone("Asia/Kolkata"); createEvent.setStart(start); EventDateTime end = new EventDateTime().setDateTime(endTime).setTimeZone("Asia/Kolkata"); createEvent.setEnd(end); EventAttendee[] attendees = new EventAttendee[] { new EventAttendee().setEmail("*****@*****.**"), new EventAttendee().setEmail("*****@*****.**"), new EventAttendee().setEmail("*****@*****.**") }; createEvent.setAttendees(Arrays.asList(attendees)); EventReminder[] reminderOverrides = new EventReminder[] {new EventReminder().setMethod("popup").setMinutes(10)}; Event.Reminders reminders = new Event.Reminders().setUseDefault(false).setOverrides(Arrays.asList(reminderOverrides)); createEvent.setReminders(reminders); String calendarId = "primary"; createEvent = service.events().insert(calendarId, createEvent).execute(); System.out.printf("Event created: %s\n", createEvent.getHtmlLink()); }
public void showEvents(Calendar calendar) throws IOException { View.header("Show Events"); Events feed = client.events().list(calendar.getId()).execute(); View.display(feed); }
public void addEvent(Calendar calendar, Event event) throws IOException { View.header("Add Event"); Event result = client.events().insert(calendar.getId(), event).execute(); View.display(result); }