【发布时间】:2020-07-07 04:48:43
【问题描述】:
问题说明:无法使用clubhouse.io api检索数据 在 Google 表格中 > 脚本编辑器
Per developers.google.com: 某些 HTTP 方法(例如,GET)不接受有效负载。 然而,俱乐部 v3 api 期望 GET 请求中的 body/payload
方法如下:
function getClubhouseStories() {
try{
var myHeaders = {"Content-Type": "application/json"};
var requestOptions = {
method: 'GET',
headers: myHeaders,
body: JSON.stringify({"query":"lable\:my label"}),
redirect: 'follow',
query: {"token": "XXXXXXXXUUIDXXXXX"},
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch("https://api.clubhouse.io/api/v3/search/stories", requestOptions);
}
catch(error) {
console.error(error);
}
var responseCode = response.getResponseCode();
var responseContent = response.getContentText();
Logger.log(responseCode);
Logger.log(responseContent);
}
返回:
responseCode >> 401
responseContent >> "{"message":"Sorry, the organization context for this request is missing. If you have any questions please contact us at support@clubhouse.io.","tag":"organization2_missing"}"
同样的请求可以通过postman 或bash 完美运行,不需要正文的请求也可以通过UrlFetchApp.fetch 运行
标签:
#clubhouse-api #google-apps-scripts #postman
【问题讨论】:
-
应该是 stackoverflow.com/questions/56200001 的副本,但帖子所有者在收到答案之前就放弃了
-
基本上,当您想要检索数据时,您不应该将有效负载传递给您的请求。
标签: bash google-apps-script postman urlfetch