Getting Started with GData API in Java

We had a few folks asking how to use GData and how to build a basic application using GData services. Here is a very simple process to get a basic Java App running which will use GData services to retrieve information from your Google Calendar. Before you go through these steps read about GData and you can also try out Google Calendar with your gmail account if you have not used it before to understand what this App is all about.

The steps below assume that you have Eclipse up and running before this step, if not go through this post for setup of Eclipse.

1. Setup GData Eclipse Plugin

Go through the url below and follow the plugin installation steps 1 to 9 from the url below
http://code.google.com/p/gdata-java-client-eclipse-plugin/wiki/Inst…

2. Download and extract GData Java Client libraries

Download Gdata Java Client Libraries from url below and extract in a local folder
http://code.google.com/p/gdata-java-client/downloads/detail?name=gd…

ip&can=2&q=

3.Download Guava libraries

Download the library from the url below and extract to a local folder
http://code.google.com/p/guava-libraries/downloads/detail?name=guav…

4. Create a GData Java Project in Eclipse

Open Eclipse and follow the steps below from Eclipse UI

Click on File New -> Other

In the New Project Popup that comes up : Select Google Data -> Google Data Project

Name the project

Select the Calendar Project Template

In the box for Google Data Client Libraries specify the location of extracted /lib folder from step 2 above

Click on Finish to create the project

5. Edit the Calendar.java code

Include your google username in the setUserCredentials function, change the highlighted parts as below

        CalendarService myService = new CalendarService(“My Application”);

        myService.setUserCredentials(“username@gmail.com”,”password”);

6. Right click on Project/select Properties

select Add External JARs ->

select the Guava Jar from step 3 above for the project

7. Build and execute the project. On the console you will see a list of calender entries being retrieved.

8. Add some calendar entries

If you have no calendar entries go to Google Calendar(https://www.google.com/calendar/renderOnline) login with your username and add a few entries. Re-execute your project and your application should retrieve the calendar entries when you execute.

You now have a working GData App. You should be able to do similar steps for Docs and other APIs. Please add comments against this post if you have issues for these steps above.

This entry passed through the Full-Text RSS service – if this is your content and you’re reading it on someone else’s site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

Technology Trendz