5

I am terribly confused on how one is to write a javascript client (non-gadget) to a private Google Spreadsheet using supported APIs? I have no difficulties getting an OAuth2 Drive API client going, but then there is no spreadsheet support!

https://developers.google.com/apis-explorer

This issue crudely asks for the spreadsheet API to appear on that page:

http://code.google.com/p/google-api-javascript-client/issues/detail?id=37

I am probably missing something obvious, so thank you for your kindness to help me...

Update:

Wow, this is kicking my behind! So, I am going down the path of attempting to take the access_token from the Oauth2 workflow and then set the gdata API Authorization header like so:

service = new google.gdata.client.GoogleService('testapp');
service.setHeaders({'Authorization': 'Bearer '+ access_token});

Unfortunately, chrome console shows that this header is not actually getting sent to google when I do something like

service.getFeed(url, cb, eb);

Uffff!

daryl
  • 1,190
  • 10
  • 19

1 Answers1

3

In order to get information from Google Spreadsheets, just send a GET request to the relevant link with the access token attached. The urlLocation is found by going to Google Drive and copying the long string of digits and letters in the url after the word "key=".

Also I used jQuery in this example.

Code:

var urlLocation = ''; //Put the Spreadsheet location here
var url = 'https://spreadsheets.google.com/feeds/list/' + urlLocation + '/od6/private/full?access_token=' + token;
$.get(url, function(data) {
    console.log(data);
});

In order to get a JSON representation, use this instead:

var urlLocation = ''; //Same as above
var url = 'https://spreadsheets.google.com/feeds/list/' + urlLocation + '/od6/private/full?alt=json-in-script&access_token=' + token + '&callback=?';
$.getJSON(url, function(data) {
    console.log(data);
});
Josh
  • 3,385
  • 5
  • 23
  • 45