成功!经过大量研究,我已经解决了这个问题。这不是有效载荷或contentType的问题(实际上,我发现.fetch自动默认为“ application /
x-www-form-urlenpred”编码)。问题出在授权上。我使用James Ferreira的Fusion
Table库作为模型,并在代码和库的
Logger.log(UrlFetchApp.getRequest(url,fetchArgs))之前插入了该表
UrlFetchApp.fetch(url, fetchArgs).getContentText()。
//log entry for library{oAuthServiceName=fusion, useIntranet=false, followRedirects=true, oAuthUseToken=always, payload=sql=INSERT INTO 1b4kT_aYRfNBy8ZPtSZqhQUqVSVIYj_QWiBmjXXI ('Heading', 'Heading 2') VALUES ('NONE','TWO'), method=POST, validateHttpsCertificates=true, contentType=application/x-www-form-urlenpred, url=https://www.google.com/fusiontables/api/query}//log entry for my pre{oAuthServiceName=fusiontables, useIntranet=false, followRedirects=true, oAuthUseToken=always, payload=sql=INSERT+INTO+1b4kT_aYRfNBy8ZPtSZqhQUqVSVIYj_QWiBmjXXI+('Heading',+'Heading+2')+VALUES+('NONE','TWO'), method=POST, validateHttpsCertificates=true, contentType=application/x-www-form-urlenpred, url=https://www.googleapis.com/fusiontables/v1/query}然后,我将工作库的日志与我自己的日志进行了比较,发现三个不同之处。
- 我认为sql语句的编码有所不同(“ INSERT INTO”与“ INSERT + INTO”)。
- 请求的“服务”参数不同(“融合”与“融合表”)。
- qpi查询网址不同。(“ www.google.com/fusiontables/api/query”与“ www.googleapis.com/fusiontables/v1/query”)。
经过一些实验,我确定…
- 假定的编码与我的错误无关。
- 服务参数也无关紧要。我在各种文档中都看到过,似乎其中任何一个都行得通。
- 令人沮丧的是,这就是问题所在。令人沮丧的是,因为api文档说要使用一种无效的方法。显然,www.googleapis.com / fusiontables / v1 / query适用于OAuth2.0。OAuthConfig(我在GAS中使用的临时授权工具)尚未迁移到2.0,因此缺少文档。我已经提交了功能请求,以将OAuthConfig迁移到此处。如果您也想解决这个问题,请给该线程一些爱。



