You can use the JavaScript JavaScript client library to request the Docs API. Although it does not come with helpers for Docs specifically, it can still be used with most APIs, including Docs. See this blog post by a Google employee for a working example.
If you end an endless authorization cycle, see this related question from Google groups. Basically, cookies are not set quickly enough, so when the JavaScript client library checks, it finds nothing and redirects to the OAuth authorization page. The solution is to either add a small delay before the check is completed, or use the login button, which initiates authorization instead of doing this when the page loads.
You will also need to add any image to your page located in the same domain. It can be hidden using CSS if in the DOM.
Using the example in the blog above, I was able to get a list of my documents using JavaScript only. Here's the modified initialization function that I used to get rid of the endless authorization loop:
function initialize() { var scope = 'http://docs.google.com/feeds/'; if (google.accounts.user.checkLogin(scope)) { var service = new google.gdata.client.GoogleService('writely', 'DocList-App-v1.0'); service.getFeed(scope + 'documents/private/full/', handleFeed, handleError); } else { var loginButton = $("<button>Click here to login</button>"); loginButton.click(function() { var token = google.accounts.user.login(scope);
Anurag Jun 18 '10 at 23:09 2010-06-18 23:09
source share