【发布时间】:2018-09-06 12:05:59
【问题描述】:
我正在试用 Wunderlist API 并一直关注此helpful tutorial。他们还提供demo on Github。它适用于 GET 调用(和 PATCH),但是当我尝试使用 POST 请求创建新任务时,它返回错误请求,客户端错误: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?
【问题讨论】:
标签: php curl guzzle wunderlist