使用奇妙清单 API 创建任务 [英] Creating Task using Wunderlist API
问题描述
在了解this(猜是这样)后,最终使用了Wunderlist API,它用于列出我的所有列表并使用给定的 list_id 列出我的所有任务.现在我正在尝试创建一个任务,给定一个 list_id:
After understanding this (guess so) and ended up using the Wunderlist API, it worked for listing all my lists and listing all my tasks with a given list_id. Now i'm trying to create a task, given a list_id:
function create_new_task(){
list_id = $("#list_id").val(); //Checked for an integer
title = $("#task_title").val(); //Checked for a string
$.ajax({
url: 'https://a.wunderlist.com/api/v1/tasks',
method: 'POST',
contentType: 'application/json',
headers: { 'X-Access-Token': access_token, 'X-Client-ID': client_id },
data: {"list_id": parseInt(list_id), "title": title.toString() }
}).success(function(data){
$("#create_new_task_modal").modal('hide');
swal("Task created!", "Your task was successfully created!", "success");
}).error(handleError);
}
但是我收到了一个 400 bad request
并带有以下非描述性错误:
But im getting a 400 bad request
with the following non-descriptive error:
{"error":"bad_request"}
有没有人以前完成过这个,或者可以看到我错过了什么?
Any one has accomplished this before or can see what am i missing?
谢谢!
更新:
现在我正在尝试使用 CURL 并且它有效.. 找不到与我的 $.ajax 实现的区别:
Now im trying to use CURL and it works.. cant find the difference with my $.ajax implementation:
curl -H "Content-Type: application/json" -H "X-Access-Token: XXX" -H "X-Client-ID: YYY" a.wunderlist.com/api/v1/tasks -X POST -d '{"list_id":1234567,"title":"hellooo"}'
推荐答案
Finally!, 这成功了.
Finally!, this did the trick.
显然我必须设置 processData: false
因为我需要发送一个字符串作为数据,而不是一个对象.还将数据更改为字符串而不是对象.
Apparently i had to set processData: false
because i needed to send a string as data, not an object. Also changing data to a string instead of an object.
这篇关于使用奇妙清单 API 创建任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!