Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON data from google spreadsheet

I went through this fiddle which have a sample of three dropdown with json data. I have a sample google spreadsheet here. Now is it possible to render this spreadsheet data to the example given at fiddle as json format. I know we can convert the spreadsheet to json as,

 var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=0AozvCNI02VmpdDkwR3RETmczbTI4ZFJhTXJkZHlUbEE#gid=0');
 query.send(handleQueryResponse);
 }
 function handleQueryResponse(response) {
    data = response.getDataTable();
    }

But using this the dropdown didn't works.

like image 962
mpsbhat Avatar asked Apr 26 '13 07:04

mpsbhat


People also ask

Does Google Sheets support JSON?

Yes, Google Sheets can import JSON files, you can do it with Google Apps Script or third-party no-code apps like Zapier.

How do I get JSON from Google Drive?

Go to Google API Console. Go to the Credentials page. Click the Download JSON button to download the client secret JSON file and securely store it in a local folder. This JSON file can then be used by Google Drive components and metadata wizard to access Google Drive via the OAuth method Installed Application (JSON) .

Can I use Google Sheets as a API?

The Google Sheets API lets you read, write, and format Google Sheets data with your preferred programming language, including Java, JavaScript, and Python.


1 Answers

I'm not sure about the way you're doing it but it can be accomplished a different way. Please see this fiddle using your example data, and below for the code.

Basically you call the JSON data from your spreadsheet with the below HTML script tags.

<script src="http://spreadsheets.google.com/feeds/list/0An1-zUNFyMVLdEFEdVV3N2h1SUJOdTdKQXBfbGpNTGc/1/public/values?alt=json-in-script&amp;callback=importGSS"></script>

Please note I'm linking to a copy of your spreadsheet as it requires it to by published

Then the you can handle the data with the below script.

function importGSS(json){
    for(var i = 0; i < json.feed.entry.length; i++){
        var entry = json.feed.entry[i];
        $('#departments').append('<option>' + entry.gsx$subdivision.$t + '</option>');
        $('#subject').append('<option>' + entry.gsx$section.$t + '</option>');
        $('#services').append('<option>' + entry.gsx$station.$t + '</option>');
    }
}

You can obviously adapt to your own needs.

like image 129
dev Avatar answered Oct 13 '22 23:10

dev