Tôi đã được tìm kiếm khá một chút bây giờ và không thể có được một cái nhìn tổng quan về Nhiệm vụ từ một danh sách duy nhất bằng cách sử dụng thiết bị đầu cuối Wunderlist: https://a.wunderlist.com/api/v1/tasksNhiệm vụ Wunderlist - làm thế nào để tôi nhận được nhiệm vụ cho một danh sách sử dụng curl trong php
Tôi có thể nhận được danh sách, thư mục và tạo danh sách, thư mục, nhiệm vụ để hoạt động tốt. Nhưng làm cách nào để tôi nhận được Công việc từ danh sách? Tôi cố gắng để giải thích các tài liệu tìm thấy ở đây: https://developer.wunderlist.com/documentation/endpoints/task
Khi tôi làm một phương thức GET tôi nhận được thông báo lỗi này:
{"error":{"type":"missing_parameter","translation_key":"api_error_missing_params","message":"Missing parameter.","title":["required"]}}
Tuy nhiên, tôi không muốn thêm tiêu đề, kể từ khi tôi làm không muốn tạo một nhiệm vụ mới, tôi chỉ muốn các nhiệm vụ của danh sách đó trở lại.
Tôi đang làm gì sai ở đây?
Đây là mã của tôi cho đến nay:
function doCall($endPoint, $parameters = array(), $method = 'GET')
{
// check if curl is available
if (!function_exists('curl_init')) {
print "This method requires cURL (http://php.net/curl), it seems like the extension isn't installed. ".__LINE__;
exit();
}
//prepare content
$parametersdata = json_encode($parameters);
// define url
$url = 'https://a.wunderlist.com/api/v1/' . $endPoint;
// init curl
$curl = curl_init();
// set options
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
// init headers
$headers = array();
// add to header
$headers[] = 'X-Access-Token: XXX';
$headers[] = 'X-Client-ID: XXX';
// method is POST, used for login or inserts
if ($method == 'POST') {
// define post method
curl_setopt($curl, CURLOPT_POST, 1);
// method is DELETE
} elseif ($method == 'DELETE') {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
} else {
curl_setopt($curl, CURLOPT_HTTPGET, 1);
}
// parameters are set
if (!empty($parameters)) {
$headers[] = 'Content-Type: application/json';
$headers[] = 'Content-Length: ' . strlen($parametersdata);
curl_setopt($curl, CURLOPT_POSTFIELDS, $parametersdata);
}
// define headers with the request
if (!empty($headers)) {
// add headers
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
// execute
$response = curl_exec($curl);
// debug is on
if (true) {
echo $method." ".$url . '<br/><pre>';
print"\n--headers--\n";
print_r($headers);
print"\n--parameters--\n";
print_r($parameters);
print"\n--parametersdata--\n";
print_r($parametersdata);
print"\n--response--\n";
print_r($response);
echo '</pre><br/><br/>';
}
// get HTTP response code
$httpCode = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);
// close
curl_close($curl);
// response is empty or false
if (empty($response)) {
//throw new Exception('Error: ' . $response);
print "Error: ". $response." ".__LINE__;
}
// init result
$result = false;
// successfull response
if (($httpCode == 200) || ($httpCode == 201)) {
$result = json_decode($response, true);
}
// return
return $result;
}
$listid = 123;
$url = 'tasks';
$tasks = doCall($url,array('list_id' => $listid), 'GET');
echo $tasks;
- EDIT PHỤ LỤC --- Tôi cũng đã thử các biến thể trong trường hợp ai thắc mắc. Tất cả họ đều cung cấp cho các lỗi tương tự "bad_request"
GET a.wunderlist.com/api/v1/tasks{"list_id":"141329591"}
GET a.wunderlist.com/api/v1/tasks{"list_id":141329591}
GET a.wunderlist.com/api/v1/tasks/{"list_id":"141329591"}
^Vui lòng thêm tài liệu bổ sung trong câu hỏi (họ có thể được chỉnh sửa), và lý tưởng nhất sau đó xóa các bình luận không cần thiết để dọn dẹp . Cảm ơn! – halfer
Đối với điểm cuối này, bạn cần gửi list_id làm tham số chuỗi truy vấn, chứ không phải dữ liệu bài đăng. Hãy thử https://a.wunderlist.com/api/v1/tasks?list_id=XXX thay thế. –