UrlFetchApp 在脚本编辑器中工作,而不是在文档中工作
UrlFetchApp works in script editor, not in document
我有一个用于表格的 Google Apps 脚本,它向 Google 图书 API 发出请求以通过 title/author 查找 ISBN,并且请求可靠地工作在脚本编辑器中测试时,但当我使用电子表格本身中的相同数据对其进行测试时,它失败并出现此错误:
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。
The URL Fetch service uses Google's network infrastructure for
efficiency and scaling purposes.
和"Google Books API results are restricted based on your server or client application's IP address" (doc)。由于某种原因,它无法确定 Google Apps 脚本 运行 和 returns 错误 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=";
我有一个用于表格的 Google Apps 脚本,它向 Google 图书 API 发出请求以通过 title/author 查找 ISBN,并且请求可靠地工作在脚本编辑器中测试时,但当我使用电子表格本身中的相同数据对其进行测试时,它失败并出现此错误:
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。
The URL Fetch service uses Google's network infrastructure for efficiency and scaling purposes.
和"Google Books API results are restricted based on your server or client application's IP address" (doc)。由于某种原因,它无法确定 Google Apps 脚本 运行 和 returns 错误 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=";