【问题标题】:Twitter API working in Postman but not in AppScripts (Google Sheets) [duplicate]Twitter API 在 Postman 中工作,但不在 AppScripts(Google 表格)中工作 [重复]
【发布时间】:2021-12-03 16:27:45
【问题描述】:

我的 twitter API 调用在 Postman 中有效,但在 AppScripts 中无效。我在两者中都设置了授权,并且使用相同的 url。

const res = UrlFetchApp.fetch(url, {
          headers:{
            Authorization: "Bearer ..."
          },
        })
  console.log("res is", res);
  return res;

这会返回“res is {}”

但在 Postman 中,使用相同 URL 和相同授权令牌的相同调用会返回:

{
  "data": {
    "id": "...",
    "name": "...",
    "username": "..."
  }
}

【问题讨论】:

  • resHTTPResponse 对象。您需要从中获取内容。有关免费资源和更多详细信息,请参阅 tag info page

标签: google-apps-script google-sheets postman urlfetch


【解决方案1】:

感谢@TheMaster 的回复。

const res = UrlFetchApp.fetch(url, {
      headers:{
        Authorization: "Bearer ..."
      },
    })

return res.getContentText();

这解决了它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 2015-11-08
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    相关资源
    最近更新 更多