我正在尝试从 JAVA 中的 Google 日历 API 获取一些信息。在尝试访问有关事件发生时间的信息时,我遇到了问题。我执行以下操作:
CalendarService myService = new CalendarService("project_name");
myService.setUserCredentials("user", "pwd");
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/private/full");
CalendarQuery q = new CalendarQuery(feedUrl);
CalendarEventFeed resultFeed = myService.query(q, CalendarEventFeed.class);
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
CalendarEventEntry g = resultFeed.getEntries().get(i);
List<When> t = g.getTimes();
//other operations
}
在 CalendarEventEntry 上使用 getTimes() 获取的列表始终为空,我不明白为什么。这对我来说似乎很奇怪,因为对于日历事件来说,它应该始终存在关于何时发生的描述......我错过了什么?
最佳答案
您必须注意单次事件与重复事件:
getTimes
用于单时间事件。
对于重复事件,您必须使用getRecurrence()
或者,您可以将 singleevents
属性设置为 true,这样重复发生的事件将作为单个事件返回,并且 getTimes 将返回一个非空列表:
CalendarQuery q = new CalendarQuery(feedUrl);
q.setStringCustomParameter("singleevents", "true");
CalendarEventFeed resultFeed = myService.query(q, CalendarEventFeed.class);
// process the results as single-events now...
引用:查找文本“singleevents”here .
注意:如果您使用 magic-cookie url 访问提要,则无论您如何在查询中设置 singleevents
属性,重复发生的事件始终会作为重复发生的事件返回。
关于java - Google 日历 API "getTimes()"方法出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2850448/