javascript - 有什么方法可以在不公开文档的情况下使用 jquery 获取 Google Doc SpreadSheet 的 JSON 数据?

标签 javascript jquery json google-docs google-docs-api

我正在尝试使用 javascript 和 jQuery 从 Google Doc 电子表格中获取数据,以便对数字进行一些数学计算。

通过我得到的下一个代码,用于公共(public)电子表格:

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 );                                                                                                                               
            }                                                                                                                                                                     
    );
}

当尝试使用私有(private)数据时,我得到了 XML 格式的数据(使用 URL: '//spreadsheets.google.com/feeds/cells/'+ key + '/' + wid + '/private/basic' )。该测试还检查可用性、防火墙、权限设置和当前用户的登录状态。

但是添加最后一部分:?alt=json-in-script&callback=f 以获取 JSON 格式的数据,抛出一个未找到,错误 404。 (如果只添加 alt=json 也会得到)。

情况总结:

       public     private
XML     yes         yes
JSON    yes       Question

http://code.google.com/intl/es/apis/gdata/docs/json.html 中描述了 JSON 对 google 的使用

google spreadsheet api 的使用在 http://code.google.com/intl/es/apis/spreadsheets/data/3.0/reference.html#WorksheetFeed

有什么方法可以在不公开文档的情况下使用 javascript 获取 GDoc 电子表格的 JSON 数据?

提前致谢

最佳答案

"Note: Retrieving a feed without authentication is only supported for published spreadsheets. "

很遗憾,因为这将是一个非常有用的功能。实际上,我很高兴了解到至少从已发布的文档中这是可能的。

关于javascript - 有什么方法可以在不公开文档的情况下使用 jquery 获取 Google Doc SpreadSheet 的 JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7527720/

相关文章:

javascript - 使用ajax作为评论表单,它给了我500内部错误,但没有脚本它可以工作,这意味着我的脚本是错误的;对吗?

javascript - jQuery - 更改文本 slider 的位置

sql - 提取所有 JSON 键

javascript - 更改 html 中当前事件段落的 css

javascript - 停止搜索引擎索引我的登录页面的最佳方法是什么?

jquery - 如何让我的按钮在我的网站中向下移动?

java - 为什么 Java 不使用 GSON 将我的对象序列化为适当的 JSON 格式?

javascript - Ember.js/Rails 嵌套 JSON

javascript - array.sort() 函数中的 "Cannot read property ' formatTime ' of undefined"错误

jQuery 选择/下拉选择器