Curl 正在发布,但 Google AppScript 没有使用相同的凭据。
我试图让谷歌应用脚本将当前文档作为 html 内容发布到新的 Jive 文档
// 以下 curl 命令完美运行
curl -u USERNAMEHERE:PASSWORDHERE -H "Content-Type: application/json" --data '{ "type": "document", "content": { "type": "text/html", "text":"<h1>HOORAY</h1> a Document is born"}, "subject": "TEST WORKED"}' https://MYJIVEURL.com/api/core/v3/places/XXXXXXXX/contents
// Apps 脚本现在抛出 401 并失败
function pleaseWork() {
var encode = Utilities.base64Encode('USER:PASS', Utilities.Charset.UTF_8);
var docbody = DocumentApp.getActiveDocument().getBody();
var subject = DocumentApp.getActiveDocument().getName();
var url = "https://JIVEURL/api/core/v3/places/XXXXXX/contents";
var option = {
authorization: "Basic " + encode,
contentType: "application/json",
method: 'post',
payload: JSON.stringify({
subject: subject,
type: "document",
content: {
type: 'text/html',
text: docbody
},
})
}
var response = UrlFetchApp.fetch(url, option).getContentText()
}```
Theres no other errors to speak of in the AppScript editor. So I must be leaving something out. I just don't know what that is