Get data from Google spreadsheet to Visualization Table.

358 views
Skip to first unread message

Webmaster NDO

unread,
Sep 1, 2015, 12:08:35 PM9/1/15
to Google Visualization API
I am trying to get data from a Google Spreadsheet. There is a problem with the javascript url/select string! When I directly ask voor data with a url like this:
https://docs.google.com/spreadsheets/d/1Cyu8C3OFV25nOw0qc2RdrGZBdrciegu-eZnkjCr2Wac/gviz/tq?sheet=AlleInschr1Dans&headers=1&tq=select%20D%2CE%2CF%2CI%2CJ%2CK%2CN%20where%20C%20%3D%20date%20"2015-10-04" 
I get an readible answer like this:
/*O_o*/
google.visualization.Query.setResponse({"version":"0.6","reqId":"0","status":"ok","sig":"2080065474","table":{"cols":[{"id":"D","label":"p1vnaam","type":"string"},{"id":"E","label":"p1tussenv","type":"string"},{"id":"F","label":"p1anaam","type":"string"},{"id":"I","label":"p2vnaam","type":"string"},{"id":"J","label":"p2tussenv","type":"string"},{"id":"K","label":"p2anaam","type":"string"},{"id":"N","label":"Dansklasse","type":"string"}],"rows":[{"c":[{"v":"Justin"},null,{"v":"Krijger"},{"v":"Lorraine"},null,{"v":"Voorn"},{"v":"Ballroom Amateurs MC"}]},{"c":[{"v":"Fred"},null,{"v":"Vierhout"},{"v":"Wilma"},null,{"v":"Vierhout-Rooswinkel"},{"v":"Ballroom Senioren 55pl 
.
.
.
}]}]}});

When I use this url to get the data via javascript like this:
 var query = new google.visualization.Query(url);

then the callback response gives me an error : Error in query: OK [400] from this responsehandler:

 query.send(handleSampleDataQueryResponse);
 
};

function handleSampleDataQueryResponse(response) {
 
if (response.isError()) {
 alert
('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
 
return;
 
}


 
var data = response.getDataTable();
 
var table = new google.visualization.Table(document.getElementById('table_div'));
 table
.draw(data, {
 height
: 700
 
});
}

It seems you cannot use the same url for the browser as for javascript. Can anyone point out the differences?

Webmaster NDO

unread,
Sep 1, 2015, 3:27:42 PM9/1/15
to Google Visualization API
Reply all
Reply to author
Forward
0 new messages