【问题标题】:Trello API PHP CurlTrello API PHP 卷曲
【发布时间】:2012-12-31 11:34:22
【问题描述】:

我正在尝试将我的网络编辑队列集成/替换到 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 等的明显引用}

【问题讨论】:

  • 我尝试了第一个错误:` 注意:未定义的变量:D:\LAMP\www\a.php 中的名称在第 21. Check is $name` 行已定义。
  • 对不起,我们可以把名字排除在外。无论如何,我想我已经解决了,但仍在研究如何解析响应。

标签: php curl trello


【解决方案1】:

这实际上似乎对我有用。我试图使用 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 />';

【讨论】:

    【解决方案2】:
    $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 />';
    

    【讨论】:

      猜你喜欢
      • 2015-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-28
      相关资源
      最近更新 更多