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
 |  Show 2 more ments

1 Answer 1

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.

本文标签: