Tasks 服务
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Tasks 服务,您可以在 Apps 脚本中使用 Google Tasks API。此 API 可让用户在 Gmail 中管理任务。
参考
如需详细了解此服务,请参阅 Tasks API 的参考文档。与 Apps 脚本中的所有高级服务一样,Tasks 服务使用的对象、方法和参数均与公共 API 相同。如需了解详情,请参阅方法签名是如何确定的。
如需报告问题并查找其他支持,请参阅 Tasks 支持指南。
示例应用
示例 Web 应用“Simple Tasks”演示了如何使用 Tasks 服务执行读取和写入操作。您可以在我们的 GitHub 代码库中查看完整源代码。
示例代码
以下示例代码使用 API 的版本 1。
列出任务列表
此示例会列出您账号中的任务列表。
列出任务
此示例会列出给定任务列表中的任务。
添加任务
此示例会将新任务添加到任务列表中。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Tasks service in Apps Script enables you to manage tasks in Gmail using the Google Tasks API.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service requires enabling before use and utilizes the same structure as the public Tasks API.\u003c/p\u003e\n"],["\u003cp\u003eSample code is provided to demonstrate common operations like listing task lists, listing tasks within a list, and adding new tasks.\u003c/p\u003e\n"],["\u003cp\u003eA simple tasks web application showcases read and write operations with the Tasks service and is available with full source code on GitHub.\u003c/p\u003e\n"],["\u003cp\u003eSupport and further information regarding the Tasks service can be found in the Tasks support guide and reference documentation.\u003c/p\u003e\n"]]],[],null,["# Tasks Service\n\nThe Tasks service allows you to use the\n[Google Tasks API](/tasks) in Apps Script. This API\ngives users the ability to manage their tasks in Gmail.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/tasks/v1/reference) for the Tasks API.\nLike all advanced services in Apps Script, the Tasks service uses the same\nobjects, methods, and parameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Tasks support guide](/tasks/support).\n\nSample application\n------------------\n\nThe sample web application Simple Tasks demonstrates how to use the Tasks\nservice for both read and write operations. You can view the full source code\non our\n[GitHub repository](https://github.com/googleworkspace/apps-script-samples/tree/main/tasks/simpleTasks).\n\n[](https://github.com/googleworkspace/apps-script-samples/tree/main/tasks/simpleTasks)\n\nSample code\n-----------\n\nThe sample code below uses [version 1](/tasks/v1/reference) of\nthe API.\n\n### List task lists\n\nThis sample lists the task lists in your account. \nadvanced/tasks.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/tasks.gs) \n\n```javascript\n/**\n * Lists the titles and IDs of tasksList.\n * @see https://developers.google.com/tasks/reference/rest/v1/tasklists/list\n */\nfunction listTaskLists() {\n try {\n // Returns all the authenticated user's task lists.\n const taskLists = Tasks.Tasklists.list();\n // If taskLists are available then print all tasklists.\n if (!taskLists.items) {\n console.log('No task lists found.');\n return;\n }\n // Print the tasklist title and tasklist id.\n for (let i = 0; i \u003c taskLists.items.length; i++) {\n const taskList = taskLists.items[i];\n console.log('Task list with title \"%s\" and ID \"%s\" was found.', taskList.title, taskList.id);\n }\n } catch (err) {\n // TODO (developer) - Handle exception from Task API\n console.log('Failed with an error %s ', err.message);\n }\n}\n```\n\n### List tasks\n\nThis sample lists the tasks within a given task list. \nadvanced/tasks.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/tasks.gs) \n\n```javascript\n/**\n * Lists task items for a provided tasklist ID.\n * @param {string} taskListId The tasklist ID.\n * @see https://developers.google.com/tasks/reference/rest/v1/tasks/list\n */\nfunction listTasks(taskListId) {\n try {\n // List the task items of specified tasklist using taskList id.\n const tasks = Tasks.Tasks.list(taskListId);\n // If tasks are available then print all task of given tasklists.\n if (!tasks.items) {\n console.log('No tasks found.');\n return;\n }\n // Print the task title and task id of specified tasklist.\n for (let i = 0; i \u003c tasks.items.length; i++) {\n const task = tasks.items[i];\n console.log('Task with title \"%s\" and ID \"%s\" was found.', task.title, task.id);\n }\n } catch (err) {\n // TODO (developer) - Handle exception from Task API\n console.log('Failed with an error %s', err.message);\n }\n}\n```\n\n### Add task\n\nThis sample adds a new task to a task list. \nadvanced/tasks.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/tasks.gs) \n\n```javascript\n/**\n * Adds a task to a tasklist.\n * @param {string} taskListId The tasklist to add to.\n * @see https://developers.google.com/tasks/reference/rest/v1/tasks/insert\n */\nfunction addTask(taskListId) {\n // Task details with title and notes for inserting new task\n let task = {\n title: 'Pick up dry cleaning',\n notes: 'Remember to get this done!'\n };\n try {\n // Call insert method with taskDetails and taskListId to insert Task to specified tasklist.\n task = Tasks.Tasks.insert(task, taskListId);\n // Print the Task ID of created task.\n console.log('Task with ID \"%s\" was created.', task.id);\n } catch (err) {\n // TODO (developer) - Handle exception from Tasks.insert() of Task API\n console.log('Failed with an error %s', err.message);\n }\n}\n```"]]