我可以使用以下方法从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());
}
Run Code Online (Sandbox Code Playgroud)
但是,这分为三个电话.有没有办法在一次通话中获取卡信息,会员信息和附件信息?该文件提到使用&fields=name,id,但似乎只来限制从基础调用返回的真实cards端点.
每次我需要卡片信息时都必须打3次API是荒谬的,但我找不到任何收集所有需要的例子.
尝试使用以下参数访问API:
/cards/[id]?fields=name,idList&members=true&member_fields=all&& attachments=true&&attachment_fields=all
特雷洛回复了我,并表示他们会像弗拉基米尔那样回答。然而,我从中得到的唯一回应是最初的卡片数据,没有附件和成员。不过,他们还引导我阅读了这篇涵盖批处理请求的博客文章。他们显然将其从文档中删除,因为它造成了混乱。
总结一下这些更改,您本质上是调用/batch,并附加一个urlsGET 参数以及要命中的端点的逗号分隔列表。最终的工作版本看起来像这样:
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);
}
Run Code Online (Sandbox Code Playgroud)