今天我创建了代码:
// 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());
}
这段代码给出了所有日历的列表。在我这里 - 一个盒子日历,一个 friend 的生日日历和一个假期日历。我需要接收今天发生的所有事件——即我的笔记、 friend 的生日和假期。我怎么做到的?
此代码返回指定数据范围内的事件,但仅适用于私有(private)日历;我试图用“allcalendars”替换“private”,但它不起作用:
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/private/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("2006-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);
最佳答案
您的问题出在您的供稿网址中。您正在使用的方法是获取默认 日历上的事件。
要获取其他日历,您应该将 url 中的 default 替换为日历的 id,例如:
feedUrl = new URL("https://www.google.com/calendar/feeds/xxxxxxxxxxxxxxxxx@group.calendar.google.com/private/full");
关于java - 从 Google 日历中提取事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7636058/