【问题标题】:UrlFetchApp.fetch in google app scripts delete url parameter谷歌应用脚​​本中的 UrlFetchApp.fetch 删除 url 参数
【发布时间】:2016-04-21 15:48:29
【问题描述】:

我正在构建一个简单的电子表格,该电子表格使用 sharedcount.com API 监控他们社交共享数据的一系列 url。

由于某种原因,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
      })

记录器函数返回正确构建的 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”。 缺少url参数!

知道发生了什么吗?

谢谢

已解决: 由于某种原因,UrlFetchApp.fetch 需要使用 https://free.sharedcount.com/url?url= 作为端点,而不仅仅是 https://free.sharedcount.com/?url=,即使在浏览器中两者工作。

【问题讨论】:

    标签: javascript rest google-apps-script google-sheets


    【解决方案1】:

    已解决: 由于某些原因,UrlFetchApp.fetch 需要使用 https://free.sharedcount.com/url?url= 作为端点,而不仅仅是 https://free.sharedcount.com/?url=,即使在浏览器中两者都可以使用。

    但欢迎提出关于为什么会发生这种情况的建议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-09
      • 1970-01-01
      相关资源
      最近更新 更多