使用纯JavaScript连接到Phabricator Conduit API

时间:2016-05-27 18:13:53

标签: api xmlhttprequest phabricator

我尝试使用纯javascript连接到Phabricator Conduit API,但没有成功。

代码示例是:

var _TOKEN = (new Date().getTime() / 1000 + "");

var connect_params: ({
   "host": _PHAB,
   "user": _USER,
   "authToken": _TOKEN,
   "clientVersion": 1.0,
   "client": "phabricator-client",
   "authSignature": hash.sha1(_TOKEN + _CERT),
});

post("/api/conduit.connect", formData, requestCallback);

function post(requestPath, dataToSend, callback) {
   var xhr = new XMLHttpRequest();

   xhr.open(requestType, phabricatorUrl + requestPath, true);

   xhr.onreadystatechange = function() {
      if (xhr.readyState === XMLHttpRequest.DONE)
         callback(JSON.parse(xhr.responseText), parseInt(xhr.status));
   }
 }

xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Content-Length", parseInt(dataToSend));
xhr.send(dataToSend);

我得到结果为json:

{"result":null,"error_code":"ERR-INVALID-CERTIFICATE","error_info":"Your authentication certificate for this server is invalid."}

1 个答案:

答案 0 :(得分:0)

我认为您错过了api.token帖子中的导管/api/conduit.connect

您可以从Settings > Conduit API Tokens

的Phabricator网络界面创建API令牌