I’m having trouble fetching calendar events from Google Calendar using their Java API. When I try to get the event feed, I keep getting a parsing error.
It seems like there’s an issue with how the API response is being parsed. Has anyone encountered this before? What’s the correct way to handle the response format?
That ParseException happens because you’re mixing the old GData library with the v3 API endpoint. Been there - ran into the same mess when I had to migrate an old project. The v3 API sends back JSON, but GData expects XML feeds, so it just chokes on the response.
You’ve got to scrap the whole approach. Ditch the manual URL construction and EventFeed stuff - use the modern Calendar service client instead. Main thing is swapping out googleCalendarService.getFeed() for the proper v3 methods.
Quick tip - try using “primary” as the calendar ID rather than the user email. Works way better in my experience. Oh, and the auth flow’s totally different now, so double-check your OAuth2 setup. Your old auth tokens won’t work with the new library.
You’re mixing deprecated GData library methods with the v3 API - that’s why it’s not working. The Calendar API v3 needs the newer Google API Client Library for Java. Try this instead:
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Your App Name")
.build();
Events events = service.events().list(calendarId)
.setTimeMin(new DateTime(System.currentTimeMillis()))
.execute();
Import from com.google.api.services.calendar.Calendar, not the old gdata packages. I hit this same problem last year updating legacy code. The auth setup’s different too - you’ll need OAuth2 credentials instead of ClientLogin. Google’s migration guide covers the auth changes pretty well.
That error happens because you’re mixing the old GData library with the newer Calendar API v3. The old library expects XML but v3 returns JSON.
Honestly, I’d skip wrestling with different API versions and just automate the whole thing. When I needed to sync calendar events across multiple systems at work, I built a workflow that handles all the API authentication and data retrieval automatically.
You set it up once and it just works. No more parsing errors or API version conflicts. You can add filters, transformations, or connect it to other services without writing more Java code.
I’ve used this for syncing team calendars and triggering notifications based on upcoming events. The automation does the heavy lifting while you focus on what actually matters.