Reputation: 1237
I just want to pull my spreadsheet into an app/website. Ideally, I'd like it to be private, but first I'm trying to bring in the data with the spreadsheet "available to the public" and "published to the web".
$.ajax({
type: 'GET',
url: 'http://spreadsheets.google.com/feeds/cells/' + spreadsheetKey + '/od6/public/full?alt=json',
success: function(data){
alert("success");
}
});
This always results in:
"You do not have view access to the spreadsheet. Make sure you are properly authenticated."
I've tried without ?alt=json, with 'list' instead of 'cells', and with 'values' instead of 'full'. Nothing works.
Also, is there a way to pass the access token into this call? I'm authenticating via Google Sign-In and allowing for Spreadsheet API scope. I've tried &accessToken=xxx and &access_token=xxx. The documentation doesn't have anything for Javascript.
Upvotes: 2
Views: 3024
Reputation: 3442
For Javascript access to a private spreadsheet, you'll need the Javascript library here: https://code.google.com/p/google-api-javascript-client/wiki/Authentication That allows you to use OAuth2.0 which allows you to access a private Google Spreadsheet. See the answer under Google Spreadsheets API with OAuth 2.0 using Javascript for a full description.
For the access token, the syntax is:
&access_token=xxx
The relevant details for Javascript is under the Protocol heading in the Google Spreadsheet API, but it isn't that helpful I've found.
To get JSON do the following:
var url = 'https://spreadsheets.google.com/feeds/list/' + urlLocation + '/od6/private/full?alt=json-in-script&access_token=' + token + '&callback=?';
$.getJSON(url, function(data) {
//do stuff with data here
});
Upvotes: 2