Warning
This page is located in archive.

Google Data Protocol

Google Data Protocol

The Google Data Protocol is a REST-inspired technology for reading, writing, and modifying information on the web. Many services at Google provide external access to data and functionality through APIs that utilize the Google Data Protocol. The protocol currently supports AtomPub and JSON formats.

The starting point for studying Google Data Protocol is here.

To access google sesvice of certain user the user needs to grand access to her/his data to your application. The user can grand access by providing her/his username and password. However, then the user is providing access to all her/his data. More flexible way is to use OAuth to provide access to specific data only (e.g. only to calendar).

OAuth is authentication process where your application does not obtain user's password. Instead you obtain Request Token which the user signs (by loging to her/his google acount and granting you access to the requested data) and your application gets Access Token and Access Token Secret which you will use to obtain the data. Access Token and Access Token Secret do not expire unless you or the user revokes them. In other words, you can securely store the Access Token and Access Token Secret and use it for all future requests for data of the user. More information about OAuth can be found here. We are using OAuth version 1.0 as version 2.0 is not supported in client libraries yet.

To identify your application to Google (and the user) you need to register it. After registration you will get Consumer Key and Consumer Secret which you will use in all requests. You dont have to register your application and use Consumer Key “anonymous” and Consumer Secret “anonymous”. However, Google will display warning that your application is not trusted when the user is signing your Request Token. Tutorial which will help you to register your application can be found here. You can register also your application running on Appspot - verify your domain by uploading file and when you download the verification file put it in war directory of your application and deploy the application to Appspot.

Excercise 1

In this exercise we will learn how to create, read, update and delete items by sending HTTP requests. This is low level API later you will this API through client libraries.

Go to the OAuth Playground. This application helps you to get access to your Google Calendar with OAuth. Then you will be able to create, read, update and delete calendars and events by sending HTTP requests.

  1. Choose scope: Calendar
  2. Get a Request Token
  3. Authorize the Request Token
  4. Upgrade to an Access Token
  5. Discover available feeds
  6. By clicking on a feed in the Request/Response window you copy the feed URL into the command line next to HTTP request (GET, POST, PUT, DELETE)
  7. By clicking on Execute button you can send the HTTP request and then study the HTTP request and response in the Request/Response window
  8. Follow this tutorial. It is recomended that you will create and use an testing acount on Google calendar to prevent that you delete your own calendars.
    1. Read your calendars
    2. Create new calendar and see the changes on Google Calendar webpage
    3. Update title of the new calendar and see the changes on Google Calendar webpage
    4. Delete the new calendar and see the changes on Google Calendar webpage

Client Libraries

Client libraries for the low level API are available here for Javascript, .NET, PHP, Python and Java. On the the download page of each library there are typically available also examples.

When you download the client libraries for Java and uzip is you need to copy jars in gdata/java/lib and gdata/java/deps folders to WEB-INF/libs folder of your project and also add them to Java Build Path of your project.

We are using client libraries for API of version 2.0 as client libraries for API of version 3.0 are available only as beta. If you are interestet in trying out the client libraries for API of version 3.0 you can download them for particular API from the API directory.

Exercise 2

Download this Eclipse project and open it. The client libraries for Java are already in WEB-INF/lib directory and added to the project build path.

Run the project, log in and grand access to your callendar. The application will display list of you calendars. The application automaticaly revokes the token when you log out.

Note that you can allways control which applications have access to your data in your Account Settings → Authorizing applications & sites.

Study the files TokenRequestServlet.java, TokenCallbackServlet.java, ReadServlet.java and TokenRevokeServlet.java to understand how OAuth works.

Try to add new functionality that adds callendar with given name (form is already provided on the page) to user's Google calendar.

You may also try to update and delete your calendars. However, it is recomended that you will create and use an testing acount on Google calendar to prevent that you delete your own calendars.

To add new functionality follow this tutorial. Note that we are using API of version 2.0. There is API of version 3.0 available, however there is only beta version of the client libraries available.

Register your domain on Appspot, change Consumer Key and Consumer Secret in source code, delete directory WEB-INF/appengine-generated and deploy your application.

Update 2013

As you noticed, at all the links in this exercise, there are big red warnings that the API is deprecated. Please study the newest Calendar API (v3) which doesn't use Google Data API, but is based on REST and JSON and the OAuth2 protocol, including the OAuth2 Playground. Try to re-write the execrise above to the new API. The best documentation is probably in the Java client library wiki. There is also a sample for the Calendar API in there, but it uses GoogleAuthorizationCodeFlow which is likely not compatible with REST. The solved exercise is here.

courses/a4m39wa2/tutorials/05/start.txt · Last modified: 2014/12/03 13:36 (external edit)