代码之家  ›  专栏  ›  技术社区  ›  Ryan

无法使用google asks脚本删除任务

  •  0
  • Ryan  · 技术社区  · 2 年前

    作为一个更大项目的一部分,我正在使用script.google.com编辑器尝试从列表中删除任务,但我一直收到一个错误,上面写着

    API call to tasks.tasks.delete failed with error: Task not found.
    

    以下是我创建的从列表中删除任务的函数:

    function deleteTask(){
    taskid = 'ajM2UDZIZGctaXJnOTJjZg';
    tasklist = 'MDk2MzE1ODgxNDkyNDE1NTI3MDA6MDow';
    try {
          // Call insert method with taskDetails and taskListId to insert Task to specified tasklist.
          Tasks.Tasks.remove(taskid, taskListId);
          // Print the Task ID of created task.
          console.log('Task with ID "%s" was deleted.', taskid);
       } catch (err) {
          // TODO (developer) - Handle exception from Tasks.move() of Task API
         console.log('Failed to move task with an error: %s', err.message);
       }
    }
    

    有趣的是,当我使用 https://developers.google.com/tasks/reference/rest/v1/tasks/delete
    它有效
    able to remove tasks from developer.google.com

    你知道我可能做错了什么吗?我知道这可能很简单,我还是javascript的新手,这很令人沮丧。如有任何帮助,我们将不胜感激

    我已经尝试使用以下代码来获取父列表ID和taskID。这似乎很有效

    const taskLists = Tasks.Tasklists.list();
        // If taskLists are available then print all tasklists.
        if (!taskLists.items) {
          console.log('No task lists found.');
          return;
        }
        // Print the tasklist title and tasklist id.
        for (let i = 0; i < taskLists.items.length; i++) {
          const taskList = taskLists.items[i];
          //console.log('Task list with title Tasks" and ID "%s" was found.', taskList.title, taskList.id);
          console.log(taskList);
        }
    
    1 回复  |  直到 2 年前
        1
  •  0
  •   Tanaike    2 年前

    修改要点:

    • 在您的演示脚本中, taskListId 未声明。所以,我认为这可能是你当前问题的原因。
    • 的论点 Tasks.Tasks.remove tasklist: string task: string 分别地如果 taskid taskListId 在您的显示脚本中分别是任务ID和任务列表ID的值, Tasks.Tasks.remove(taskid, taskListId); 应该是 Tasks.Tasks.remove(taskListId, taskid); 。我认为这可能也是一个问题。

    当这些点反映在脚本中时,它将变为如下所示。

    修改的脚本:

    function deleteTask() {
      const taskId = '###'; // Please set your task ID.
      const taskListId = '###'; // Please set your task list ID.
      try {
        Tasks.Tasks.remove(taskListId, taskId);
        console.log('Task with ID "%s" was deleted.', taskId);
    
      } catch (err) {
        // TODO (developer) - Handle exception from Tasks.move() of Task API
        console.log('Failed to move task with an error: %s', err.message);
      }
    }
    
    • 通过此修改,的任务 taskListId, taskId 被移除。

    笔记

    • 在这个修改中,它假设您的任务ID和任务列表ID是有效值。请小心。

    参考

    推荐文章