Problem with Google Calendar API "getTimes()" method
I'm trying to get several informations from google calendar's API in JAVA. While trying to access to informations about the time of an event I got a problem. I do the following:
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();开发者_Go百科 i++) {
CalendarEventEntry g = resultFeed.getEntries().get(i);
List<When> t = g.getTimes();
//other operations
}
The list t obtained with getTimes() on a CalendarEventEntry is always empty and I can't figure out why. This seems strange to me since for a calendar event it should always exist a description of when it should happen... what am I missing??
You have to be aware or single time events vs recurring events:
getTimes
is used for single time events.
For recurring events you have to use getRecurrence()
Or, you can set the singleevents
property to true, so recurring events are returned as single events and getTimes will return a non-empty list:
CalendarQuery q = new CalendarQuery(feedUrl);
q.setStringCustomParameter("singleevents", "true");
CalendarEventFeed resultFeed = myService.query(q, CalendarEventFeed.class);
// process the results as single-events now...
Reference: look for the text "singleevents" here.
Note: if you use a magic-cookie url to access the feed, then recurring events are always returned as recurring events, no matter how you set the singleevents
property in the query.
This Google support request is also relevant. (The same answer Toto provided but with additional information)
精彩评论