我正在建立一个简单的电子表格,使用sharedcount.com API监控一系列网址以获取社交分享数据。
由于某种原因,UrlFetchApp.fetch()消除了我作为要询问的端点参数传递的URL。
这是我的代码:
var sheet = SpreadsheetApp.getActiveSheet(),
urls = sheet.getRange('A:A').getValues().slice(1),
apikey = "XXXXXXXXXXXXXXXXX",
apiEndPoint = "https://free.sharedcount.com/"
data = [];
urls.forEach(function(url, idx) {
apiurl = apiEndPoint + '?url=' + encodeURIComponent(url) + '&apikey=' + apikey
Logger.log(apiurl)
sharedCountData = UrlFetchApp.fetch(apiurl)
data[idx] = sharedCountData
})
logger函数返回正确构建的url(例如:https://free.sharedcount.com/?url=http%3A%2F%2Fwww.teamvaxitalia.it%2F&apikey=XXXXXXXXXXXXXX),但运行我的代码时,当它到达fetch()时会收到401错误,其中传递的端点是:https://free.sharedcount.com/?url=&apikey=XXXXXXXXXXXXXX错误是"不是有效的网址"。 url参数丢失了!
对于发生了什么有什么想法?
由于
解决: 出于某种原因,使用UrlFetchApp.fetch需要使用https://free.sharedcount.com/ url?url = 作为端点,而不仅仅是https://free.sharedcount.com/ ?url = ,甚至如果在浏览器中都可以工作。
答案 0 :(得分:1)
解决: 出于某种原因,使用UrlFetchApp.fetch需要使用https://free.sharedcount.com/url?url=作为端点,而不仅仅是https://free.sharedcount.com/?url=,即使在浏览器中也能正常工作。
但欢迎提出有关为何发生这种情况的建议。