java - 从 Google 日历中提取事件

标签 java android google-calendar-api

今天我创建了代码:

// 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/

相关文章:

java - 在运行时在 netbeans 中创建组件

java - 如何使用控制台启动器从命令行运行 JUnit5 测试?

java - 使用警报管理器广播数据

java - 我应该如何在Android问答游戏中创建question_bank?

pdf - 使用 GAS 将带有事件的 Google 日历导出为 PDF

java - 如何在Java中使用RegEx?

java - 隐藏和显示 Sprite 和引擎 Android

android - (x..x).map 在 kotlin android 中做什么

google-calendar-api - Google Calendar API : Editing a single occurrence of a recurring event

php - 过滤事件列表 Google Calendar PHP