文件中的Curl请求:
curl -X POST -d "xls_url=https://kc.kobotoolbox.org/ukanga/forms/tutorial/form.xls" https://kc.kobotoolbox.org/api/v1/forms我的应用程序脚本
function patchForm() {
//Other details saved in scriptProperties
var payload = "https://docs.google.com/spreadsheets/d/e/.../pub?
output=xlsx";
//Published spreadsheet, I think this is essentially an xlsx file stored in a url?
var scriptProperties = PropertiesService.getScriptProperties();
var url = "https://kc.kobotoolbox.org/api/v1/forms/...";
var params = {
"method" : scriptProperties.getProperties()["method"],
"headers": {"Authorization" : scriptProperties.getProperties()["Authorization"]},
"xls_url": payload
};
Logger.log(params)
UrlFetchApp.fetch(url, headers = params)
return(UrlFetchApp.fetch(url, headers = params));}
如何转换:
"xls_url=https://kc.kobotoolbox.org/ukanga/forms/tutorial/form.xls"在url抓取章中的api文档中。
谢谢你,不是真正的程序员。
如果我不能让google分支机构工作,有没有办法通过google脚本发送卷发请求?
发布于 2021-06-12 06:27:46
我相信你的目标如下。
修改要点:
xls_url的属性在params of rlFetchApp.fetch(url, params)中不存在。xls_url=https://kc.kobotoolbox.org/ukanga/forms/tutorial/form.xls的值作为表单数据发送。当上述要点反映到Google脚本中时,如下所示。
修改脚本:
function patchForm() {
var url = "https://kc.kobotoolbox.org/api/v1/forms";
var params = {
method: "POST", // In this case, even when this line is removed, the POST method is used.
payload: {xls_url: "https://kc.kobotoolbox.org/ukanga/forms/tutorial/form.xls"}
};
var res = UrlFetchApp.fetch(url, params);
Logger.log(res.getContentText())
}注意:
https://docs.google.com/spreadsheets/d/e/.../pub?output=xlsx而不是https://kc.kobotoolbox.org/ukanga/forms/tutorial/form.xls时,请替换它。"Authorization" : scriptProperties.getProperties()["Authorization"]。如果需要使用,请按以下方式将其包含到上面的脚本中。在这种情况下,它假设您的scriptProperties.getProperties()["Authorization"]值是有效值。请小心这个。
var scriptProperties = PropertiesService.getScriptProperties();var params ={ method:" POST ",//在本例中,即使删除了该行,也使用POST方法。有效载荷:{xls_url:"https://kc.kobotoolbox.org/ukanga/forms/tutorial/form.xls"},headers:{“授权”:https://kc.kobotoolbox.org/ukanga/forms/tutorial/form.xls"} };参考资料:
https://stackoverflow.com/questions/67946057
复制相似问题