[Java]Google Data Java Client API

Posted 31 August 2010 - 01:55 AM

Introduction:

The Google Data Protocol is an Application Programming Interface released by Google Inc. This API creates an interface which gives a developer tools to search and interact with many of the different services provided by google. (Google Docs, Google Calender, Youtube etc...)The Google Data(GData) API has a library for many different languages; this tutorial covers the Java Client. In this tutorial I will cover installation of the GData Java client eclipse plug-in, a brief overview of many of the APIs and finally an example using the Code Search library.

Installation:
If you want to install the packages yourself, you will need:

If you would prefer instead to use eclipse and are using version 3.6. Open eclipse and go to
Help -> Install New Software -> Add
Name : whatever
Location: http://gdata-java-cl...vn/update-site/

check the box and hit next. Ensure that Google Data Feature is selected -> next -> next -> accept software license and continue through the prompts until you see the frame that has download software dependencies. Click the box that downloads them and save them where you like.After the eclipse plug-in is installed, you know have an environment in which to work with the API.

Google Code Search allows you to search public source code. The advantages from being able to search other peoples code has effectively increased my understanding of topics. It is one thing to read you open a URL and open a stream to a InputStreamReader being used by a BufferedReader, it is a completely different and much easier to understand when you see.

This is the benefit Google Code Search affords you. Using the API is very straight forward, it uses POSIX regexp to control everything.
Regexp: http://en.wikipedia....ular_expression
There are many different parameters to search by:
regexp Search for a regular expression

To try out Code Search through your browser connect to google.com/codesearch
To understand how the API works you must understand the Google Data Protocol and how information requests are made and processed in the API.http://code.google.c...2.0/basics.html

Coding Example:

Consider that I want to query the GData so I can recieve the first link for a specific search. For example if you want to search for “Hello World.java”. The string you send to the CodeSearchService would be “lang:java%20Hello%20World”

This class will connect to google search RSS feed at “http://www.google.com/codesearch/feeds/search?q=” and query it with codeSearchStatement.
and return the result in a CodeSearchFeed. The resultFeed is then put into a List<CodeSearchEntry> entries so that they can be processed through. Because of the way I set this up it only returns the first entry but the feed by default returns 10 at a time.

Ending Notes:

When I first started playing with Google Data I had to change my classpath to point to the collections library in google data. This can be done by right clicking on your package name going to run as: -> Run Configurations -> Classpath
Enter the directory that the GData collections library was saved to, for me it is:
C:\Users\tsama\Desktop\gdata\java\deps\ and selecting google-collect-1.0-rc1.