奇妙清单的 API 和 Guzzle - 创建任务 - 错误请求 400

Wunderlist’s API with Guzzle - Create Task - Bad Request 400

我正在试用奇妙清单 API 并且一直在关注这个 helpful tutorial. They also provide a demo on Github。它适用于 GET 调用(和 PATCH),但是当我尝试使用 POST 请求创建新任务时,它 returns 错误请求,客户端错误:400.

WunderlistClient.php

public function createTask($name, $list_id, $task = []) {
    if (!is_numeric($list_id)) {
        throw new \InvalidArgumentException('The list id must be numeric.');
    }
    $task['name'] = $name;
    $task['list_id'] = $list_id;
    $response = $this->client->post('tasks', ['body' => json_encode($task)]);
    $this->checkResponseStatusCode($response, 201);
    return json_decode($response->getBody());
}

index.php

try {
    $created = $wunderlist->createTask('New Task', $list_id);
    dump($created);
}
catch(\Exception $exception) {
    dump($exception);
}

我添加了一个 createList 函数,它只需要标题,而且确实有效。

public function createList($title, $list = []) {
    $list['title'] = $title;
    $response = $this->client->post('lists', ['body' => json_encode($list)]);
    $this->checkResponseStatusCode($response, 201);
    return json_decode($response->getBody());
}

为什么我无法创建 tasks

我只需要将 'name' 切换为 'title'。

public function createTask($title, $list_id, $task = []) {
    if (!is_numeric($list_id)) {
        throw new \InvalidArgumentException('The list id must be numeric.');
    }
    $task['title'] = $title;
    $task['list_id'] = $list_id;
    $response = $this->client->post('tasks', ['body' => json_encode($task)]);
    $this->checkResponseStatusCode($response, 201);
    return json_decode($response->getBody());
}