Вопрос

I am having an issue where I need to pull back the current event's listed in someones default Google calendar, perhaps for a week. I listed the best code example I can find below, but it does not have anything that points to the Oauth2 call in it. Also, I get an error for service. but I cannot find anything that would possibly reference it including the accessProtectedResource object.

Could someone explain what service is supposed to be, or a link to an example that will give me the calendar events after an Oauth2 call?

CalendarList calendarList = service.calendarList().list().execute();

    while (true) {
      for (CalendarListEntry calendarListEntry : calendarList.getItems()) {
        System.out.println(calendarListEntry.getSummary());
      }
      String pageToken = calendarList.getNextPageToken();
      if (pageToken != null && !pageToken.isEmpty()) {
        calendarList =     service.calendarList().list().setPageToken(pageToken).execute();
      } else {
        break;
      }
    }
Это было полезно?

Решение

Took me a while to get this since the Google documentation is there, but it has an error in it.

Calendar service3 = new Calendar(transport, jsonFactory, accessProtectedResource);

com.google.api.services.calendar.model.Calendar calendar = service3.calendars().get("primary").execute();
com.google.api.services.calendar.model.Events events = service3.events().list("primary").execute(); 

Другие советы

You can refer

https://developers.google.com/google-apps/calendar/v1/developers_guide_java

Displaying Google Calendar in Java JFrame

https://developers.google.com/google-apps/calendar/v2/developers_guide_java

Code something like this

// Create a CalenderService and authenticate
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("jo@gmail.com", "mypassword");

// Send the request and print the response
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);
System.out.println("Your calendars:");
System.out.println();
for (int i = 0; i<resultFeed.getEntries().size(); i++) {
  CalendarEntry entry = resultFeed.getEntries().get(i);
  System.out.println("\t" + entry.getTitle().getPlainText());
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top