Google Task API:无法插入带有标题的任务列表

时间:2018-10-20 03:25:16

标签: javascript google-api google-api-client google-tasks-api google-tasks

我正在尝试使用Google API客户端插入任务列表。 以下是我使用的方法:

function insertTaskList(taskId = "test-id", taskListTitle = "Test title"){
    gapi.client.tasks.tasklists.insert({
      'method': 'POST',
      'body': {
          "kind": "tasks#taskList",
          "id": taskId,
          "title": taskListTitle
      }
    }
    ).then(function(response){
      console.log("task list inserted")
      console.log(response)
    }
    )
}

调用上面的方法insertTaskList,将插入一个空白任务列表,而不考虑我要传递的标题和ID。我试图找到将请求正文部分放在插入函数中的位置,但是我在其他地方发现的唯一建议是将其作为 body resource 包括在内。

我已经在SO(Specify request body in Google API calls (using Google APIs Client Library for JavaScript))上提到了这个问题,但这对我也不起作用。

更新: 在尝试了几种组合之后,当我只通过标题而没有其他任何方法时,它就起作用了。

function insertTaskList(taskId = "test-id", taskListTitle = "Test title"){
    gapi.client.tasks.tasklists.insert({
      'resource': {
          "title": taskListTitle
      }
    }
    ).then(function(response){
      console.log("task list inserted ")
      console.log(response)
    }
    )
}

我仍然想知道如何通过传递ID来使其工作,因为我想拥有自己的ID,并且在Google api的页面上说ID应该是字符串。所以我不确定,我到底在做什么错。

https://developers.google.com/tasks/v1/reference/tasklists#resource的资源表示形式

{
  "kind": "tasks#taskList",
  "id": string,
  "etag": string,
  "title": string,
  "updated": datetime,
  "selfLink": string
}

0 个答案:

没有答案
相关问题