【问题标题】:How to send an action using a webhook in trello?如何在 trello 中使用 webhook 发送操作?
【发布时间】:2020-05-01 23:33:15
【问题描述】:

每当在我的 trello 板上创建卡片时,我都会尝试在我的卡片上创建评论。我可以访问我的 Api 密钥和令牌。

    $json = file_get_contents("php://input");
    $data = json_decode($json,true);
    $fp = fopen("myjson.txt",'w');
    fwrite($fp,$json);
    fclose($fp);
    $id = (string) $data["action"]["data"]["card"]["id"];
    $actionThatTriggered = (string) $data["action"]["type"];

   if($actionThatTriggered == "createCard"){
     $ch = curl_init();
     curl_setopt($ch,CURLOPT_URL,"https://api.trello.com/1/cards/".$id."/actions/comments?text=hello+world&key=".$apikey."&token=".$tokennumber);
     curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
     curl_setopt($ch,CURLOPT_POST,true);
     curl_setopt($ch,CURLOPT_HEADER,false);
     $server_response = curl_exec($ch);
     curl_close($ch);
}

我可以将来自 webhook 的响应存储在 myjson.txt 中,但无法发送 curl POST 请求来评论创建的卡片。我已将此文件托管在正在运行的 apache2 服务器上。

另外,当我通过我的内核独立运行这个脚本时,我可以在我的卡上看到一条新的评论。我认为在服务器上托管文件存在一些问题。

我是网络新手,所以详细的解释会很有帮助。

【问题讨论】:

    标签: php curl trello


    【解决方案1】:

    默认情况下,json_decode 返回对象,如果您希望在关联数组中返回输出,则必须将第二个参数作为布尔值“true”传递。 因此,将第二行替换为以下内容:

    $data = json_decode($json, true);
    

    【讨论】:

      猜你喜欢
      • 2015-11-02
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      • 2022-07-09
      • 2013-08-19
      • 1970-01-01
      相关资源
      最近更新 更多