I am trying to get data from a Google Doc Spreadsheet, using javascript and jQuery, in order to do some math with the numbers.
With the next code I got it, for public spreadsheets:
function getdata( key, wid, f )
{
return $.getJSON(
'//spreadsheets.google.com/feeds/cells/' +
key + '/' + wid + '/public/basic?alt=json-in-script&callback=?',
function( data ){
/* the content of this function is not important to the question */
var entryidRC = /.*\/R(\d*)C(\d*)/;
var retdata = {};
retdata.mat = {};
for( var l in data.feed.entry )
{
var entry = data.feed.entry[ l ];
var id = entry.id.$t;
var m = entryidRC.exec( id );
var R,C;
if( m != null )
{
R = new Number( m[ 1 ] );
C = new Number( m[ 2 ] );
}
var row = retdata.mat[ R ];
if( typeof( row ) == 'undefined' )
retdata.mat[ R ] = {};
retdata.mat[ R ][ C ] = entry.content;
}
if( typeof( f ) != 'undefined' )
f( retdata )
else
console.log( retdata );
}
);
}
When tried for private ones, I got the data in XML (using the URL:
'//spreadsheets.google.com/feeds/cells/'+ key + '/' + wid + '/private/basic'
). This test checks also for the availability, the firewall, the permission setup and the login state of the current user.
But adding the last part: ?alt=json-in-script&callback=f
to get the data in JSON, throws an Not found, Error 404. (Also got if only alt=json
is added).
Summary of situation:
public private
XML yes yes
JSON yes Question
The use of JSON against google is described in http://code.google.com/intl/es/apis/gdata/docs/json.html
The use of google spreadsheet api is described in http://code.google.com/intl/es/apis/spreadsheets/data/3.0/reference.html#WorksheetFeed
Any way to get JSON data of a GDoc SpreadSheet using javascript without make the doc publicly available?
Thanks in advance
"Note: Retrieving a feed without authentication is only supported for published spreadsheets."
Shame, because this would be a very useful feature. As it is, I'm pleased to learn that this is possible at least from published docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With