Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to get JSON data of a Google Doc SpreadSheet using jquery without make the doc public?

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

like image 534
robermorales Avatar asked Sep 23 '11 10:09

robermorales


1 Answers

"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.

like image 55
graphicdivine Avatar answered Oct 17 '22 17:10

graphicdivine