Do not use gdata-java-api
Posted in code, opinion on March 28th, 2012 by ben – Be the first to commentTL;DR
- Google offers two libraries for accessing their services, the gdata-api and google api
- The older one looks more complete, and with a promise to maintain it, it’s tempting
- Don’t give in – take the time to deal with the newer API
A current project of mine involves using Google Docs and automating a workflow using Google App Engine (GAE) with Java. There are two libraries provided by Google for accessing their services, an older library called “gdata“, and a newer, called “google api.” The older comes with the warning:
We have stopped actively developing this client library, except critical bug fixes and support for some Google API’s. However, this client library is not deprecated, and is considered the “stable” choice, unless you have a specific requirement that is only supported by the new client library below.
The newer comes with a nice migration message, but also with the caveat regarding the generic Data APIs (and the specific Document List service I wanted)
We do not provide service-specific libraries for the Google Data APIs because they are built on an older infrastructure that does not have a Discovery Service. Nevertheless, the base Google API Client Library for Java fully supports Google Data APIs as long as you write your own Atom XML data model
The last emphasis is mine, and it scared me away from using it, reasoning, “why should I write my own data model when a complete one exists?”
Here’s a stack of reasons why:
- gdata does not come with any maven support. I did find a script to add the jars to my maven repository, though.
- gdata has manual hoops to get working with OAuth. Although they have the recipe fully documented, they still have this zinger, “you need some way to persist the token secret in order to create an OAuth token object coming back from the approval page.” They vaguely suggest, “set a session variable or cookie,” but they don’t provide any sample code that closes the loop.
- gdata has archaic dependencies. Its latest release is completely incompatible with the newer API, since the newer depends on a recent release of guava, but gdata still depends on google-collections-rc1. See Issue 244 for an example. You can’t accuse of the guava folks of premature deprecation – they kept the old methods in for 2 years before removing the deprecated calls.
- Despite promises of “gdata-java-client is not deprecated. We are keeping it in maintenance mode, fixing critical bugs, and adding a few minimal features,” the code doesn’t support this. Again, see issue 244 where a patch has been submitted and its still sitting there.
- I really wanted to use the “changes” feed from the Document List API. Although there are ExtensionPoint classes such as Changestamp and LargestChangestamp in the library, no samples referenced them, and questions in the forums about why they weren’t working go unanswered. I couldn’t get changestamp data out of the old classes, which is what eventually caused me to change course
- Writing custom Atom XML beans isn’t that bad. @Key is your friend, and there are plenty of samples.
I’m still at a loss for why a Google Data API is not fully fleshed out. The calls are well defined, there’s just some effort involved in doing all the mapping. Perhaps there’s a measurable performance penalty of mapping all the XML into beans that is offset by the effort required to write all the ones you need.
Hopefully this post will save someone else the same missteps. It’s not about reinventing the wheel, but learning from other peoples experiences.
