douju2014 2015-05-26 11:47
浏览 74
已采纳

PHP Curl / Todoist /添加项目

I am trying to add an item with the todoist API using PHP Curl according to this:

https://developer.todoist.com/?shell#add-an-item

It quotes this code:

$ curl https://todoist.com/API/v6/sync -X POST \
    -d token=0123456789abcdef0123456789abcdef01234567 \
    -d commands='[{"type": "item_add", "temp_id": "43f7ed23-a038-46b5-b2c9-4abda9097ffa", "uuid": "997d4b43-55f1-48a9-9e66-de5785dfd69b", "args": {"content": "Task1", "project_id": 128501470}}]'

I am trying this in PHP:

$args = '{"content": "Task1", "project_id":'.$project_id.'}';
    $url = "https://todoist.com/API/v6/sync";
    $post_data = array (
        "token" => $token,
        "type" => "item_add",
        "args" => $args,
    );

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_POST, 1);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

    $output = curl_exec($ch);

    curl_close($ch);

So I have the token, the args, the type but I can't seem to get it to work.

What would the PHP equivalent of that call be?

  • 写回答

2条回答 默认 最新

  • douba2705 2015-05-26 12:20
    关注

    Try this:

    $url = "https://todoist.com/API/v6/sync";
    $post_data = [
        'token' => $token,
        'commands' => 
            '[{"type": "item_add", ' .
            '"temp_id": "43f7ed23-a038-46b5-b2c9-4abda9097ffa", ' .
            '"uuid": "997d4b43-55f1-48a9-9e66-de5785dfd69b", ' . 
            '"args": {"content": "Task1", "project_id":'.$project_id.'}}]'
    ];
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $url);
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    curl_setopt($ch, CURLOPT_POST, 1);
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    
    $output = curl_exec($ch);
    
    curl_close($ch);
    

    I haven't tested it, but I'm pretty sure this is the equivalent curl command implemented in PHP. Let me know how it works out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作