rob*_*les 9 javascript jquery json google-docs google-docs-api
我正在尝试使用javascript和jQuery从Google Doc电子表格中获取数据,以便对数字进行一些数学计算.
对于公共电子表格,我得到了下一个代码:
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 );
}
);
}
Run Code Online (Sandbox Code Playgroud)
当尝试私有的时,我得到了XML数据(使用URL :)
'//spreadsheets.google.com/feeds/cells/'+ key + '/' + wid + '/private/basic'.此测试还检查当前用户的可用性,防火墙,权限设置和登录状态.
但添加最后一部分:?alt=json-in-script&callback=f以JSON格式获取数据,抛出Not found,错误404.(如果只alt=json添加,也会得到).
情况概要:
public private
XML yes yes
JSON yes Question
Run Code Online (Sandbox Code Playgroud)
http://code.google.com/intl/es/apis/gdata/docs/json.html中介绍了如何对谷歌使用JSON
http://code.google.com/intl/es/apis/spreadsheets/data/3.0/reference.html#WorksheetFeed中介绍 了google电子表格api的使用
有没有什么方法可以使用javascript获取GDoc SpreadSheet的JSON数据而不公开该文档?
提前致谢