简体   繁体   English

应用程序脚本中的Google Fusion Table REST Api与高级服务Fusion Table Services

[英]Google Fusion Table REST Api vs Advanced Services Fusion Table Services in app scripts

I am very confused about the correct or recommended mechanism to use for accessing google fusion tables APIs in app scripts. 对于在应用程序脚本中访问Google融合表API所使用的正确或推荐的机制,我感到非常困惑。 There seem to be two methods with examples but no discussion about which is preferred or why. 似乎有两种带有示例的方法,但是没有讨论哪个是首选还是为什么。 Is one of these interfaces newer and preferred while the other is dying? 这些接口中的一个是较新的且更受欢迎的,而另一个正在消失吗? Is one obsolete or more restricted in what it can do? 一个人过时或受到更多限制吗?

Method 1 is the REST API described here 方法1是此处描述的REST API

https://developers.google.com/fusiontables/docs/v2/sql-reference#Select https://developers.google.com/fusiontables/docs/v2/sql-reference#Select

Method 2 is a set of library functions sort of described here under the Apps Script/Google Advanced Services: 方法2是一组库函数下面在Apps脚本/ Google Advanced Services下进行了描述:

https://developers.google.com/apps-script/advanced/fusion-tables https://developers.google.com/apps-script/advanced/fusion-tables

For example, using the REST api to do a dql query, we end up with something like this: 例如,使用REST api进行dql查询,我们最终得到如下结果:

function runSQL(sql){
  var getDataURL = 'https://www.googleapis.com/fusiontables/v1/query?sql='+sql;
  var dataResponse = UrlFetchApp.fetch(getDataURL,getUrlFetchOptions()).getContentText();  
  return dataResponse;
}

And using the advanced API we use something like this: 使用高级API,我们使用类似以下内容的东西:

result = FusionTables.Query.sql(sql, { hdrs: false });

The REST API seems much harder to use, requireing complex oAuth and developer keys to be configured in advance and coded into the application while the Advanced Services API harvests all this behind the scenes and makes for simple API calls like I show here. REST API似乎更难使用,需要预先配置复杂的oAuth和开发人员密钥并将其编码到应用程序中,而Advanced Services API会在幕后收集所有这些信息,并进行简单的API调用,如我在此处所示。

I have seen numerous examples using each of the above with no hint as to why one author chose her mechanism instead of the other. 我已经看到了许多使用上述每种方法的示例,但都没有暗示为什么一个作者选择了她的机制而不是另一个。

Your help is greatly appreciated. 非常感谢您的帮助。

The service within app-script is a work in progress, so the full functionality of the API might not be fully supported at the moment. app-script中的服务尚在开发中,因此目前可能不完全支持API的全部功能。 As you mentioned though, the big advantage of the service over the REST API is that you do not have to handle the OAuth flow, as you only need to enable it on your script (as stated here ). 正如你提到的,虽然,在REST API 服务的一大好处是,你不必处理OAuth流,因为你只需要启用它在你的脚本(如说在这里 )。

The Apps Script "advanced service" implementation still lacks some advanced functionality (like alt=media format queries or multipart / resumable uploads) -- if it actually has those features, it lacks extremely basic documentation of them, to the point that the Apps Script editor autocomplete is unaware of them. Apps Script的“高级服务”实现仍然缺少一些高级功能(例如alt=media格式查询或分段/可恢复的上载)-如果它确实具有这些功能,则缺少它们的极其基础的文档,以至于Apps Script编辑器自动完成功能不知道它们。 The tradeoff of these functionality gaps is that you don't need to handle keys, request building, etc. 这些功能差距的折衷是您不需要处理密钥,请求构建等。

So, if you're doing simple sql select / importRows work, the Advanced Service should be able to cover almost all your needs. 因此,如果您正在执行简单的sql select / importRows工作,那么Advanced Service应该能够满足您的几乎所有需求。 If you need to delete from your FusionTables, you might want to consider setting up the REST API - because deleting is 1 record per query, the better way to delete is to instead "download what you want to keep, then re-upload it back via replaceRows ." 如果您需要从FusionTables中删除,则可能需要考虑设置REST API-因为删除是每个查询1条记录,所以删除的更好方法是改为“下载要保留的内容,然后重新上传回来通过replaceRows 。”

(This worked for me for a while, but eventually what I was keeping outgrew the Apps Script service's limitations and I began receiving Empty Response errors from the call to replaceRows . My remedy was to perform my record maintenance tasks via the REST API, where I can specify resumable uploads, timeouts, etc., while more "normal" interactions are done through the Advanced Service.) (这对我replaceRows了一段时间,但最终我一直超出了Apps Script服务的限制,我开始从对replaceRows的调用中收到“ Empty Response错误。我的补救方法是通过REST API执行记录维护任务,可以指定可恢复的上传,超时等,而更多的“常规”互动是通过高级服务完成的。)

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

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