admin管理员组文章数量:1323735
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/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/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 .html
The use of google spreadsheet api is described in .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
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./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./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./intl/es/apis/gdata/docs/json.html
The use of google spreadsheet api is described in http://code.google./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
Share Improve this question asked Sep 23, 2011 at 10:38 robermoralesrobermorales 3,5632 gold badges28 silver badges37 bronze badges 7- it is my first question, please vote/ment in order I can improve my style – robermorales Commented Sep 23, 2011 at 10:54
-
1
Presumably
&callback=f
is a typo, and you mean&callback=?
– graphicdivine Commented Sep 23, 2011 at 11:18 -
when I am in the address bar of a browser, I use
=f
, from jquery I use=?
. Thanks anyway. – robermorales Commented Sep 23, 2011 at 11:21 - 1 "Note: Retrieving a feed without authentication is only supported for published spreadsheets." ~~ code.google./apis/gdata/samples/spreadsheet_sample.html – graphicdivine Commented Sep 23, 2011 at 11:42
- Thank you very much for the answer! At least I can stop searching. Please, post an answer, so I can accept it and mark the question as solved, since it will be useful to somebody in the future. – robermorales Commented Sep 23, 2011 at 22:13
1 Answer
Reset to default 6"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.
本文标签:
版权声明:本文标题:javascript - Any way to get JSON data of a Google Doc SpreadSheet using jquery without make the doc public? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742119401a2421626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论