I’m working with Java and the Google Data API to fetch event details from a public calendar. I need to get the location data from calendar events but I’m having trouble with the output format.
Here’s what I’ve tried:
private static void fetchEvents(CalendarService calService, URL calendarURL)
throws IOException, ServiceException {
CalendarFeed feed = calService.getFeed(calendarURL, CalendarFeed.class);
for(int j = 0; j < feed.getEntries().size(); j++) {
CalendarEntry calEvent = feed.getEntries().get(j);
System.out.println("\t" + calEvent.getLocations());
}
}
When I run this code, the console shows strange output like:
[com.google.gdata.data.extensions.Where@2a4f6bc8]
[com.google.gdata.data.extensions.Where@2a4f6bc8]
The method documentation says it should return a List but I’m getting these object references instead of actual location text. What am I doing wrong here? How can I get the actual location string from these Where objects?
I also tried getting event dates but that’s not working either:
private static List<When> fetchEventTimes(CalendarEntry calEvent) {
return calEvent.getRepeatingExtension(When.class);
}
for(int j = 0; j < feed.getEntries().size(); j++) {
CalendarEntry calEvent = feed.getEntries().get(j);
List<When> dates = fetchEventTimes(calEvent);
System.out.println("\t" + j + ". " + calEvent.getTitle().getPlainText() + "\t" + dates.get(0).getValueString());
}
This returns null values for all entries. Any suggestions on how to properly extract the location and date information from the XML response?