GData Gadget

This document describes how to build an iGoogle gadget that access a Google Data API feed to access a user's private data. It uses a feature called the OAuth Proxy which can also be used in a more generalized form to access REST APIs exposed by different websites which support an Internet standard called OAuth which providess controlled access to a user's private data with the permission of that user.

Step 1

Make a copy of the following sample gadget that uses GData

http://monsur.googlepages.com/contacts.xml

You can also view a walk through of how this sample gadget works.

Change the request_url parameter in the OAuth section to refer to the Google Data REST API endpoint that you want to access. The sample gadget connects to the Google Contacts endpoint.

For example, the sample gadget has the line:

url="https://www.google.com/accounts/OAuthGetRequestToken?scope=http://www.google.com/m8/feeds/"

If you were accessing Google Finance you could change it to:

url="https://www.google.com/accounts/OAuthGetRequestToken?scope=http://finance.google.com/finance/feeds/"

Note: There is some public documentation on this parameter in the Gadgets API reference for the makerequest function that supports the OAuth signature option. If you want to learn more about makerequest, you can read the original documentation as well as some enhancements that were made to it to support the OpenSocial platform.

Step 2

Step 3

In the FetchData function of the sample gadget, there are three changes that need to be made

Change 1

Change the URL parameter so that it calls the desired GData endpoint.

For example, the sample gadget has the line:

url = 'http://www.google.com/m8/feeds/contacts/default/base';

If you were trying to access the user's list of Google Finance portfolios you could change it to:

url = 'http://finance.google.com/finance/feeds/default/portfolios';

Change 2

At the bottom of the FetchData function of the sample gadget, change the "service" parameter to load the JavaScript classes for the particular GData service that you are accessing.

For example, the sample gadget has the line:

var service = new google.gdata.contacts.ContactsService('testapp');

If you were trying to access the the Google Calendar service you could change it to:

var service = new google.gdata.calendar.CalendarService('testapp');

If you do want to access the raw results of the Google Data request, and do not want to use application specific helper classes, then use the google.gdata.client.Service function.

Change 3:

Then change the service.getContactFeed function to instead use the application specific version of this function.

For example, the sample gadget has the line:

service.getContactFeed(url, callback, callback);

If you were trying to access the Google Calendar feed you could change it to:

service.getCalendarsFeed(url, callback, callback);

If you do want to access the raw results of the Google Data request, and do not want to use application specific helper classes, then use the service.getFeed function.

Step 4

Modify the ShowResults function of the sample gadget to parse the data returned by the Google Data function and display the results in some basic way so you can confirm the gadget is properly communicating with the Google Data endpoint. The sample gadget expects to get a list of a user's contacts and displays them. You can use the Google Data JavaScript library to make it easier to interact with the results returned by the Google Data request. That library has specific support for a few applications such as Calendar, Blogger, & Contacts. For other applications you can still use the google.gdata.client class to provide basic helper functions.

If you are interested in JavaScript library support for other applications, please let us know because we prioritize the development of them based on developer feedback.

Step 5

One common complaint is that the workflow that an end-user must go through to approve your gadget's access to the end-user's data. However you can modify your gadget so that after the user goes through that approval flow, they will be automatically redirected back to your gadget, and the gadget can them immediately load their data. To do this in iGoogle, you will redirect the user to an iGoogle URL that includes a reference to your gadget. The details of this are TBD

You may notice that gadgets developed by Google themselves do not go through this approval process. For example, the gadget http://dirk.balfanz.googlepages.com/contacts.xml will access your Google Mail contact list. That is because we maintain a whitelist of specific gadgets Google has built which we trust to access specific data, for example the official Google Book Search gadget is trusted to access the Google Book Search API. However as a matter of policy we do not add gadgets developed outside Google to that whitelist.

Step 6

Your gadget should now work. You can then start customizing the gadget as needed to create the desired user experience.