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

相關問題