【问题标题】:Trello API: get members, attachments, and card information in one call?Trello API:一次调用获取成员、附件和卡片信息?
【发布时间】:2017-02-01 20:07:23
【问题描述】:

我可以使用这个从 Trello API 获取数据:

private function get_card_info($card_id) {
    $client =         new \GuzzleHttp\Client();
    $base =           $this->endpoint . $card_id;
    $params =         "?key=" . $this->api_key . "&token=" . $this->token;      
    $cardURL =        $base . $params;
    $membersURL =     $base . "/members" . $params;
    $attachmentsURL = $base . "/attachments" . $params;

    $response = $client->get($cardURL);
    $this->card_info['card'] = json_decode($response->getBody()->getContents());

    $response = $client->get($membersURL);
    $this->card_info['members'] = json_decode($response->getBody()->getContents());

    $response = $client->get($attachmentsURL);      
    $this->card_info['attachments'] = json_decode($response->getBody()->getContents());
}

但是,这分为三个调用。有没有办法一键获取卡信息、会员信息、附件信息? docs 提到使用 &fields=name,id,但这似乎只是限制了从基本调用返回到 cards 端点的内容。

每次我需要卡片信息时都必须点击 API 3 次,这很荒谬,但我找不到任何收集所需信息的示例。

【问题讨论】:

    标签: php trello


    【解决方案1】:

    尝试使用以下参数访问 API:

    /cards/[id]?fields=name,idList&members=true&member_fields=all&& attachments=true&&attachment_fields=all

    【讨论】:

    • 我一回到我的个人笔记本电脑就会检查这个。这是在任何地方的文档中吗?
    【解决方案2】:

    Trello 回复了我,并表示他们会像 Vladimir 那样回答。然而,我得到的唯一回应是最初的卡片数据,没有附件和成员。但是,他们也将我引导至涵盖批处理请求的this blog post。由于它造成的混乱,他们显然将其从文档中删除。

    为了总结这些更改,您实际上是调用/batch,并附加一个urls GET 参数和一个逗号分隔的端点列表以命中。工作的最终版本最终看起来像这样:

    private function get_card_info($card_id) {
        $client =         new \GuzzleHttp\Client();
        $params =         "&key=" . $this->api_key . "&token=" . $this->token;
    
        $cardURL = "/cards/" . $card_id;
        $members = "/cards/" . $card_id . "/members";
        $attachmentsURL = "/cards/" . $card_id . "/attachments";
    
        $urls = $this->endpoint . implode(',', [$cardURL, $members, $attachmentsURL]) . $params;
    
        $response = $client->get($urls);
        $this->card = json_decode($response->getBody()->getContents(), true);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 2012-05-01
      • 2016-12-19
      • 2017-11-02
      • 2017-10-06
      • 1970-01-01
      相关资源
      最近更新 更多