1

我有一个表单的Google Apps脚本,它向Google Books API请求按标题/作者查找ISBN,并且在脚本编辑器中进行测试时请求可靠地工作,但是当我在电子表格本身相同的数据进行测试时,出现此错误:UrlFetchApp在脚本编辑器中工作,而不在文档中

Request failed for https://www.googleapis.com/books/v1/volumes?q=Deedy%2C%20Carmen%20Agra%2014%20Cows%20for%20America returned code 403. Truncated server response: { "error": { "errors": [ { "domain": "global", "reason": "unknownLocation", 
"message": "Cannot determine user location for geogra... (use muteHttpExceptions option to examine full response) (line 55). 

这是具有相同数据的脚本编辑器中运行相同功能的执行成绩单,成功:

[16-08-05 14:39:09:772 EDT] Starting execution 
[16-08-05 14:39:10:558 EDT] UrlFetchApp.fetch([https://www.googleapis.com/books/v1/volumes?q=Deedy%2C%20Carmen%20Agra%2014%20Cows%20for%20America]) [0.778 seconds] 
[16-08-05 14:39:10:559 EDT] HTTPResponse.getResponseCode() [0 seconds] 
[16-08-05 14:39:10:559 EDT] HTTPResponse.getContentText() [0 seconds] 
[16-08-05 14:39:10:569 EDT] Logger.log([found title match for '%s': '%s', [14 Cows for America, 14 Cows for America]]) [0 seconds] 
[16-08-05 14:39:10:583 EDT] Logger.log([result: %s, [9781561454907]]) [0 seconds] 
[16-08-05 14:39:10:584 EDT] Execution succeeded [0.804 seconds total runtime] 

我制作了source code可用,如果它是相关的。

回答

1

The URL Fetch service uses Google's network infrastructure for efficiency and scaling purposes.

和(doc)“谷歌图书API结果是基于服务器或客户端应用程序的IP地址限制”。由于某些原因,它无法确定服务器的Google Apps脚本运行位置,并返回错误Cannot determine user location for geographically restricted operation。你可以尝试发送参数country,只是改变这一行:

var isbnEndpoint = "https://www.googleapis.com/books/v1/volumes?q="; 

这样:

var isbnEndpoint = "https://www.googleapis.com/books/v1/volumes?country=US&q="; 
+0

奇怪,它可以检测,但不能在现场的电子表格dev的服务器上的位置,但没错,这工作,谢谢。 – adrusi

相关问题