开发者

Extracting events from Google Calendar

开发者 https://www.devze.com 2023-04-10 22:05 出处:网络
Today I created code: // Create a CalenderService and authenticate CalendarService myService = new CalendarService(\"exampleCo-exampleApp-1\");

Today I created code:

// Create a CalenderService and authenticate
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("j...@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());
}

This code gives out the list of all calendars. At me - a box calendar, a calendar of birthdays of friends and a calendar of holidays. I need to receive all events occurring today - i.e. both my notes, and birthdays of friends, and holidays. How I am able to do it?

This code returns event for specified data range, but it is work for private calendar only; i tried to replace "private" for "allcalendars", but it doesn't work:

URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/private/full");

CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("20开发者_StackOverflow中文版06-03-16T00:00:00"));
myQuery.setMaximumStartTime(DateTime.parseDateTime("2006-03-24T23:59:59"));

CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("jo@gmail.com", "mypassword");

// Send the request and receive the response:
CalendarEventFeed resultFeed = myService.query(myQuery, Feed.class);


Your problem is in the your feed url. The one you are using is getting the events on the default calendar.

To get the other calendars you should replace default in the url by the calendar's id, for example:

feedUrl = new URL("https://www.google.com/calendar/feeds/xxxxxxxxxxxxxxxxx@group.calendar.google.com/private/full");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号