Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve data from Google Spreadsheet to Javascript or JSON?

This is public spreadsheet created using Google Drive: https://docs.google.com/spreadsheets/d/1hA4LKZn9yKoqnSzaI6_73GQSj_ZVpB3O0kC93QM98Vs/pubhtml

How to retrieve data from Google Spreadsheet to Javascript or JSON with new Google Spreadsheets API version 3.0 ?

like image 531
MicRum Avatar asked Jan 11 '23 13:01

MicRum


1 Answers

You can access a cell-based basic feed using the following URL structure: https://spreadsheets.google.com/feeds/cells/1hA4LKZn9yKoqnSzaI6_73GQSj_ZVpB3O0kC93QM98Vs/od6/public/basic?alt=json . By default the feed is in XML form, however, you can request JSON format using alt=json query parameter.

This feed also supports JSONP requests, so an example of fetching this data from a browser with jQuery might look like:

var url = "https://spreadsheets.google.com/feeds/cells/1hA4LKZn9yKoqnSzaI6_73GQSj_ZVpB3O0kC93QM98Vs/od6/public/basic?alt=json";
$.ajax({
    url:url,
    dataType:"jsonp",
    success:function(data) {
        // data.feed.entry is an array of objects that represent each cell
    },
});
like image 137
lucasjackson Avatar answered Jan 17 '23 09:01

lucasjackson