数据JSON到Active Collab的未格式化

时间:2019-12-23 15:23:13

标签: php json api activecollab

我正在尝试在API中向Active Collab调用GET。我需要列出任务,但是这些数据一团糟地返回,可以帮到我吗?

我的代码是:

$ch = curl_init();
        $token = 'token';
        curl_setopt_array($ch, [
            CURLOPT_URL => 'https://collab.business.com.br/api/v1/projects/numberproject/tasks/',
            CURLOPT_POST => false,
            CURLOPT_HTTPHEADER => [
                'X-Angie-AuthApiToken: ' . $token,
                'Content-Type: application/json',
                'x-li-format: json'
            ],
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_PROTOCOLS => CURLPROTO_HTTPS
        ]);
        $resultado = curl_exec($ch);
        $tasks = json_decode($resultado, true);
        $task_list_id = 55979;
        for ($i = 0; $i < count($tasks); $i++) {
            if ($tasks[$i]["task_list_id"] == $task_list_id) {
                $tasks_name[$i] = $tasks[$i]["name"];
            }
        }
        print_r($tasks_name);
        curl_close($ch);
        return $tasks_name;
    }

    listTasks();

这是我的代码的回报:

Notice: Undefined offset: 0 in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 21

Notice: Undefined offset: 1 in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 21

Notice: Undefined offset: 2 in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 21

Notice: Undefined offset: 3 in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 21

Notice: Undefined offset: 4 in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 21

Notice: Undefined offset: 5 in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 21

Notice: Undefined offset: 6 in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 21

Notice: Undefined offset: 7 in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 21

Notice: Undefined variable: tasks_name in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 25

Notice: Undefined variable: tasks_name in C:\xampp\htdocs\tagsreports\class\listTasks.php on line 27

这返回到我的代码,其中我的print_r是$ tasks:

$tasks 要求我输入$结果的结果,但是当我输入print_r($ result)时;显示的值与$ tasks

相同

$resultado

0 个答案:

没有答案