Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script UrlFetchApp在脚本编辑器中工作,而不是在文档中_Google Apps Script_Google Sheets_Google Spreadsheet Api - Fatal编程技术网

Google apps script UrlFetchApp在脚本编辑器中工作,而不是在文档中

Google apps script UrlFetchApp在脚本编辑器中工作,而不是在文档中,google-apps-script,google-sheets,google-spreadsheet-api,Google Apps Script,Google Sheets,Google Spreadsheet Api,我有一个用于工作表的Google Apps脚本,它向Google Books API请求按标题/作者查找ISBN,在脚本编辑器中进行测试时,这些请求可靠地工作,但当我使用电子表格中的相同数据对其进行测试时,它失败了,出现以下错误: Request failed for https://www.googleapis.com/books/v1/volumes?q=Deedy%2C%20Carmen%20Agra%2014%20Cows%20for%20America returned code 40

我有一个用于工作表的Google Apps脚本,它向Google Books API请求按标题/作者查找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]
如果相关的话,我已经准备好了

URL获取服务使用谷歌的网络基础设施 效率和可扩展性

和“GoogleBooksAPI结果受服务器或客户端应用程序IP地址的限制”()。由于某些原因,它无法确定运行Google Apps脚本的服务器位置,并返回错误
无法确定地理限制操作的用户位置
。您可以尝试发送参数
country
,只需更改此行:

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

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

令人惊讶的是,它可以检测到dev服务器上的位置,但不能检测到实时电子表格上的位置,但是是的,这很有效,谢谢。