1
我嘗試了所有可以考慮的組合來完成此項工作。我需要發送到新Basecamp API作爲POST
字段才能讓它接受我的POST數據?Google Apps Script Basecamp POST
我的代碼是:
function getFilterBy() {
var url = "https://basecamp.com/****/api/v1/projects/*****.json";
var payload = {"name" : "myapp", "description" : "no desc mls"};
var opt = {
"contentType" : "application/json",
"method" : "POST",
"headers":{ "User-Agent": "myapp ([email protected])",
"Authorization" :"Basic " + Utilities.base64Encode("user" + ":" + "pass")},
"validateHttpsCertificates" :false,
"muteHttpExceptions" : true,
"payload" : payload
};
var response = UrlFetchApp.fetch(url, opt);
var text = response.getContentText();
Logger.log(text);
}
我的錯誤是:
lexical error: invalid char in json text.
description=no+desc+mls&name=Ho
(right here) ------^
我試圖Utilities.jsonStringify
,但沒有運氣。我知道它是一個noob錯誤,但我無法弄清楚。如果有一個地方你知道我在哪裏可以得到這個信息,那將是驚人的。
謝謝!
更新1
function getFilterBy() {
var url = "https://basecamp.com/****/api/v1/projects/****.json";
var payload = {name : 'myApp Change'};
var opt = {
"contentType" : "application/json",
"method" : "POST",
"headers":{ "User-Agent": "myApp ([email protected])",
"Authorization" :"Basic " + Utilities.base64Encode("user" + ":" + "pass")},
"validateHttpsCertificates" :false,
"muteHttpExceptions" : true,
"payload" : Utilities.jsonStringify(payload)
};
var response = UrlFetchApp.fetch(url, opt);
var text = response.getContentText();
Logger.log(text);
}
息率錯誤:
<body>
<div class="dialog">
<div class="innercol">
<h1>Hmm, that isn’t right</h1>
<h2>You may have typed the URL incorrectly.</h2>
<p>Check to make sure you’ve got the spelling, capitalization, etc. exactly right.</p>
</div>
</div>
<p id="back" class="back">
<a href="javascript:window.history.back();">← Back to previous page</a>
</p>
<script type="text/javascript">
if (window.history.length <= 1) document.getElementById("back").style.display = "none";
</script>
</body>
這確實工作,創建一個新的項目,但不能編輯現有項目的一些重新一個兒子。 – 2013-03-19 16:51:31
如果出現這種情況,您不應該得到您指定的錯誤。你會得到一個不同的錯誤 - 它不應該是關於「JSON文本中的無效字符」。 – 2013-03-19 17:16:10
我的歉意,我添加了一個更新。謝謝。 – 2013-03-19 17:38:35