简体   繁体   English

如何使用XHR获得SpreadSheet Google?

[英]How can I get a SpreadSheet Google using XHR?

I'm trying to get Spreadsheet data Google. 我正在尝试获取Google的电子表格数据。 So, to do this, I've seen the Query Language Reference and basic information about Query object and, in this second link, it appears the "fast" info to realize a query. 因此,为此,我看了《 查询语言参考》有关Query对象的基本信息 ,在第二个链接中,它似乎是实现查询的“快速”信息。 The problem is that, because of my JS skills, I don't understand opt_options parameter of the google.visualization.Query function. 问题是,因为我的JS的技能, 我不明白 opt_options的参数google.visualization.Query功能。

I mean, I know that I have to send my query to get the data, but I don't know how to do it because the sendMethod description of opt_parameters doesn't seems me sufficiently detailed for write the JS code whether I want use the XHR method. 我的意思是,我知道我必须发送查询才能获取数据,但是我不知道该怎么做,因为opt_parameterssendMethod描述似乎opt_parameters不够详细,无法编写JS代码。 XHR方法。

Also I've seen that I can include the query in the SpreadSheet link. 我也看到我可以在SpreadSheet链接中包含查询。 Anyways, I only want to get the data transformed into JSON data or something that I can manipulate. 无论如何,我只想将数据转换为JSON数据或我可以操纵的东西。

I consider that this question can be useful for this people like me that are beginning to get data from other pages and don't know how to do it exactly. 我认为这个问题对像我这样的人可能会有用 ,这些人开始从其他页面获取数据并且不知道该怎么做。

PD: Yes, I've read XMLHttpRequest info from MDN. PD:是的,我已经从MDN中读取XMLHttpRequest信息。

EDIT: I've supposed that Query object send XHR and I only have to concern me for send method of Query and its callback that is an instance of QueryResponse class. 编辑:我假设Query对象发送XHR,而我只需要关心Query send方法及其作为QueryResponse类实例的回调。 The problem is that I don't retrieve anything! 问题是我什么也没找到! Here is my code once again: 这是我的代码再次:

var query;

function getData(DATA_SOURCE_URL){
    query = new google.visualization.Query(DATA_SOURCE_URL);
    query.setTimeout(10);
    query.send(displayData);
    console.log("Query has been sent");
}

function displayData(response){ //This function doesn't works
    if(response.isError()){
        console.log(response.getDetailedMessage());
    }
    var data = response.getDataTable();
    alert(data);
}

Thanks in advance! 提前致谢!

(Posted answer on behalf of the OP). (代表OP发布答案)。

Finally I got rid of Query Language Reference and all stuff about Google and I discovered TableTop to request data from spreadsheets. 最终,我摆脱了“查询语言参考”和关于Google的所有知识,我发现TableTop从电子表格中请求数据。 It's very easy to use and its documentation is simple and concise. 它非常易于使用,其文档也非常简洁。 My main aim was bring data from a spreadsheet to my JS application. 我的主要目的是将电子表格中的数据导入我的JS应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM