开发者

Google tasks update error

I am attempting to update a task with the following code:

function updtsk(task,id)
{
  var url = 'https://www.googleapis.com/tasks/v1/lists/@default/tasks/'+id;
  va开发者_Python百科r req = {
    'method': 'PUT',
    'headers': {
      'Content-type': 'application/json'
    },
    'body': JSON.stringify(task)
  };
  var addDone = function(resp, xhr) {
    if (xhr.status != 200) {
      notifyFailure('Couldn\'t update task.', xhr.status);
      return;
    }

    //notifySuccess(task['title']);
  }

  oauth.sendSignedRequest(url, addDone, req);
}

I get the following error however:

"{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}
"

The update body is this:

{
 'title': $(this).val()
};

I am using the chrome_ex_oauth api and could use some help.


Try passing the 'id' key/value pair together with the title information you are already sending.

I had this same problem, even using the API explorer. There's no documentation to indicate this is a required parameter, especially since it is included in the URL. Once I added id, it worked properly.


It's possible you need to include additional fields in the update.

The documentation here: http://code.google.com/apis/tasks/v1/reference.html#resource_tasks appears to indicate the status property is not optional (the other mutable fields are listed as optional in their descriptions). You may also need to include the kind property with the static value indicated there.


In Google Task API for updating any TaskList Task:
First we have to get task with use of TaskList Id and Task Id
Second step change/update in task and again update that task.
Hope this is helpful for you.


I read these answers several times, but only saw what I thought I already knew, which was wrong. The documentation for insert/update/etc. states

POST https://www.googleapis.com/tasks/v1/lists/tasklist/tasks

It is the id of the tasklist being modified (e.g. something like "MTA1MjEpoqwdNTMzMjAzo349YDA6MDow") and not the title of the tasklist e.g. "My Task List" that needs to be passed in the POST request header, e.g.

POST https://www.googleapis.com/tasks/v1/lists/MTA1MjEpoqwdNTMzMjAzo349YDA6MDow/tasks

You can find the id of the list by doing a tasklists 'list' query.

GET https://www.googleapis.com/tasks/v1/users/@me/lists

which returns, e.g. something like this:

{
   "kind": "tasks#taskList",
   "id": "MTA1MjEpoqwdNTMzMjAzo349YDA6MDow",
   "title": "My Task List",
   "updated": "2019-03-15T21:21:03.000Z",
   "selfLink": "https://www.googleapis.com/tasks/v1/users/@me/lists/MTA1MjE0Njc5NTMzMjA1NDk0NDA6MDM1NDgwMjIxODgyMjcyODow"
  }

You can see the tasklist id in the response, which can then be used in the POST to modify the desired tasklist. Answers to this question have been posted, but none with explicit examples. Hopefully this example will help someone get past this newbie kind of problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜