duangang3832 2013-01-17 00:43
浏览 25
已采纳

Trello API PHP卷曲

I am trying to integrate/replace my web edit queue into Trello.

I made an organization which is not public but have created a token for read/write access.

I haven't seen a good PHP wrapper for the Trello API (have looked at the two available and couldn't really get them up and running for my purposes.)

Anyway, what I'd like to do is provide rather rudimentary access to read and insert cards to a particular list.

I have gotten as far as using the API to return the results of a List using the following:

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

I get exactly what I want as a result, json of the cards in the list.

Now I;m trying to recreate that in PHP using CURL and I'm getting an error response of unauthorized or bad request from whatever I try in the following code:

$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);

So I'm just looking to see if anyone knows what I'm doing wrong. I feel like it should be simple but I've spent a couple hours on it and I think I need some help. Let me know if you have any ideas.

{i have left out obvious references to my API key, token, BoardID etc}

  • 写回答

2条回答 默认 最新

  • duanjiao4763 2013-01-17 15:58
    关注

    This actually seems to work for me. I was trying to use POST instead of the default GET with CURL. Still working on parsing the response but it seems like I'm on the right track. Got an "200 OK" in the response.

    $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 />';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?