0

我正在尝试将我的网络编辑队列集成/替换到 Trello 中。

我创建了一个不公开的组织,但创建了一个用于读/写访问的令牌。

我还没有看到一个好的 Trello API 的 PHP 包装器(已经查看了两个可用的并且无法真正让它们为我的目的启动和运行。)

无论如何,我想做的是提供相当基本的访问权限来读取卡片并将卡片插入特定列表。

我已经使用 API 返回列表的结果,使用以下内容:

https://api.trello.com/1/lists/[mylistID]/cards?key=[myappkey]&token=[mytoken]

结果,我得到了我想要的结果,列表中卡片的 json。

现在我正在尝试使用 CURL 在 PHP 中重新创建它,并且我在以下代码中尝试的任何内容都收到了未经授权或错误请求的错误响应:

$url = "https://api.trello.com/1/lists/[myboardID]/cards";
$trello_key          = 'mykey';
$trello_list_id      = 'mylistid';
$trello_member_token = 'mytoken'; 

$fields = "key=$trello_key&token=$trello_member_token&name=$name&idList=$trello_list_id";
e
# init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // make sure we see the sended header afterwards
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_POST, 1);

# dont care about ssl
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

# download and close
$output = curl_exec($ch);
$request =  curl_getinfo($ch, CURLINFO_HEADER_OUT);
$error = curl_error($ch);
curl_close($ch);

所以我只是想看看是否有人知道我做错了什么。我觉得它应该很简单,但我已经花了几个小时,我想我需要一些帮助。如果您有任何想法,请告诉我。

{我遗漏了对我的 API 密钥、令牌、BoardID 等的明显引用}

4

2 回答 2

2

这实际上似乎对我有用。我试图使用 POST 而不是带有 CURL 的默认 GET。仍在努力解析响应,但似乎我走在正确的轨道上。在响应中得到“200 OK”。

$url = 'https://api.trello.com/1/lists/[myListID]/cards?key=[MyApiKey]&token=[myToken]';

# init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_fields);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // make sure we see the sended header afterwards
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
//curl_setopt($ch, CURLOPT_POST, 1);

# dont care about ssl
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

# download and close
$output = curl_exec($ch);
$request =  curl_getinfo($ch, CURLINFO_HEADER_OUT);
$error = curl_error($ch);
curl_close($ch);

echo 'This is output = '.$output .'<br />';
echo 'This is request = '.$request .'<br />';
echo 'This is error = '.$error .'<br />';
于 2013-01-17T15:58:39.557 回答
0
$url = 'https://api.trello.com/1/boards/[myListID]/cards?key=[MyApiKey]&token=[myToken]';

# init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_fields);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // make sure we see the sended header afterwards
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
//curl_setopt($ch, CURLOPT_POST, 1);

# dont care about ssl
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

# download and close
$output = curl_exec($ch);
$request =  curl_getinfo($ch, CURLINFO_HEADER_OUT);
$error = curl_error($ch);
curl_close($ch);

echo 'This is output = '.$output .'<br />';
echo 'This is request = '.$request .'<br />';
echo 'This is error = '.$error .'<br />';
于 2018-11-09T10:59:27.633 回答