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; }
public Calendar addCalendarsUsingBatch(String nameCalendar) throws IOException { View.header("Add Calendars using Batch"); BatchRequest batch = client.batch(); // Create the callback. JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() { public void onSuccess(Calendar calendar, GoogleHeaders responseHeaders) { View.display(calendar); addedCalendarsUsingBatch.add(calendar); } @Override public void onFailure(GoogleJsonError e, GoogleHeaders responseHeaders) { System.out.println("Error Message: " + e.getMessage()); } }; // Create 2 Calendar Entries to insert. Calendar entry1 = new Calendar().setSummary(nameCalendar); client.calendars().insert(entry1).queue(batch, callback); // Calendar entry2 = new Calendar().setSummary("Calendar for Testing 2"); // client.calendars().insert(entry2).queue(batch, callback); batch.execute(); return entry1; }
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); }
public Calendar addCalendar() throws IOException { View.header("Add Calendar"); Calendar entry = new Calendar(); entry.setSummary("My agenda"); Calendar result = client.calendars().insert(entry).execute(); View.display(result); return result; }
public Calendar updateCalendar(Calendar calendar) throws IOException { View.header("Update Calendar"); Calendar entry = new Calendar(); entry.setSummary("Updated Calendar for Testing"); Calendar result = client.calendars().patch(calendar.getId(), entry).execute(); View.display(result); return result; }
public void deleteCalendarsUsingBatch() throws IOException { View.header("Delete Calendars Using Batch"); BatchRequest batch = client.batch(); for (Calendar calendar : addedCalendarsUsingBatch) { client .calendars() .delete(calendar.getId()) .queue( batch, new JsonBatchCallback<Void>() { public void onSuccess(Void content, GoogleHeaders responseHeaders) { System.out.println("Delete is successful!"); } @Override public void onFailure(GoogleJsonError e, GoogleHeaders responseHeaders) { System.out.println("Error Message: " + e.getMessage()); } }); } batch.execute(); }
public Calendar getCalendars(String name) throws IOException { View.header("Show Calendars"); CalendarList feed = client.calendarList().list().execute(); Calendar calendar = null; for (CalendarListEntry entry : feed.getItems()) { System.out.println(); System.out.println("-----------------------------------------------"); if (entry.getSummary().matches(name)) { calendar = client.calendars().get(entry.getId()).execute(); return calendar; } } return null; }
private void loadHistory(UpdateInfo updateInfo, boolean incremental) throws Exception { Calendar calendar = getCalendar(updateInfo.apiKey); String pageToken = null; long apiKeyId = updateInfo.apiKey.getId(); settingsService.getConnectorSettings(updateInfo.apiKey.getId()); List<String> existingCalendarIds = getExistingCalendarIds(apiKeyId); List<CalendarListEntry> remoteCalendars = new ArrayList<CalendarListEntry>(); List<CalendarConfig> configs = new ArrayList<CalendarConfig>(); do { final long then = System.currentTimeMillis(); final Calendar.CalendarList.List list = calendar.calendarList().list().setPageToken(pageToken); final String query = list.getUriTemplate(); CalendarList calendarList = null; try { calendarList = list.execute(); countSuccessfulApiCall(updateInfo.apiKey, updateInfo.objectTypes, then, query); } catch (IOException e) { countFailedApiCall( updateInfo.apiKey, updateInfo.objectTypes, then, query, ExceptionUtils.getStackTrace(e), list.getLastStatusCode(), list.getLastStatusMessage()); } if (calendarList == null) throw new Exception("Could not get calendar list, apiKeyId=" + updateInfo.apiKey.getId()); List<CalendarListEntry> items = calendarList.getItems(); for (CalendarListEntry item : items) { existingCalendarIds.remove(item.getId()); remoteCalendars.add(item); configs.add(entry2Config(item)); } pageToken = calendarList.getNextPageToken(); } while (pageToken != null); initChannelMapping(updateInfo.apiKey, configs); updateInfo.setContext(REMOTE_CALLENDARS_KEY, remoteCalendars); for (CalendarListEntry remoteCalendar : remoteCalendars) loadCalendarHistory(calendar, remoteCalendar, updateInfo, incremental); deleteCalendars(apiKeyId, existingCalendarIds); }
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()); }
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 Settings getSettings(Calendar service) throws IOException { Settings settings = service.settings().list().execute(); return settings; }
public void deleteCalendar(Calendar calendar) throws IOException { View.header("Delete Calendar"); client.calendars().delete(calendar.getId()).execute(); }
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); }
public Setting getSetting(Calendar service, String settingId) throws IOException { Setting setting = service.settings().get(settingId).execute(); return setting; }
public void showCalendars() throws IOException { View.header("Show Calendars"); CalendarList feed = client.calendarList().list().execute(); View.display(feed); }