google-tasks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDrive Google Tasks via . The user's OAuth bearer token is
in ; every call needs it as
. At minimum the token
carries plus the identity scopes
(); if the user opted in to write at install
time it also carries the broader scope (read + write).
curl + jq$GOOGLE_TASKS_TOKENAuthorization: Bearer $GOOGLE_TASKS_TOKENtasks.readonlyopenid email profiletasksThe Tasks API returns standard JSON; failures surface as
— show that
error verbatim. means the token expired (re-install). on a write means the user only granted
— ask them to re-install with the read+write box
checked.
{"error": {"code": 401|403|..., "message": "..."}}401403 insufficientPermissionstasks.readonlyAlways start with to discover which task lists
the account has — the user's default plus any extras they created on
calendar.google.com or in the Tasks app.
users/@me/listsBefore bulk creates / completions / deletes echo the exact
titles back to the user and ask them to confirm. Don't trash a
task by guessing an id.
通过操作Google Tasks。用户的OAuth bearer token存储在中;每次调用都需要将其作为携带。该令牌至少需要包含权限以及身份范围();如果用户在安装时选择了写入权限,还会包含更广泛的权限(读写)。
curl + jq$GOOGLE_TASKS_TOKENAuthorization: Bearer $GOOGLE_TASKS_TOKENtasks.readonlyopenid email profiletasksTasks API返回标准JSON格式;失败时会返回——需原样展示该错误信息。表示令牌已过期(需重新安装)。执行写入操作时出现,说明用户仅授予了权限——请提示用户重新安装并勾选读写权限选项。
{"error": {"code": 401|403|..., "message": "..."}}401403 insufficientPermissionstasks.readonly始终从开始,以获取账户下的所有任务列表——包括用户的默认列表以及他们在calendar.google.com或Tasks应用中创建的其他列表。
users/@me/lists在批量创建/完成/删除任务前,需将具体任务标题回显给用户并请求确认。不要通过猜测ID来删除任务。
Recipes
操作示例
Verify auth + list all task lists (always run first)
验证授权并列出所有任务列表(务必先执行此操作)
sh
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq '.items[] | {id, title, updated}'The default list is usually titled "我的任务" / "My Tasks" but the
id (a long opaque string like ) is what every
subsequent call needs.
MTAxMjM0NTY3OAlists/{id}/taskssh
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq '.items[] | {id, title, updated}'默认列表的标题通常为“我的任务” / "My Tasks",但后续所有调用都需要用到id(一个类似的长随机字符串)。
lists/{id}/tasksMTAxMjM0NTY3OAList all unfinished tasks across every list
列出所有列表中的未完成任务
sh
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq -r '.items[] | "\(.id)\t\(.title)"' | while IFS=$'\t' read LIST_ID LIST_TITLE; do
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode 'showCompleted=false' \
--data-urlencode 'maxResults=100' \
| jq --arg list "$LIST_TITLE" '.items[]? | {list: $list, title, due, status, notes}'
done | jq -s '. | sort_by(.due // "9999")'showCompleted=falseshowCompleted=true&showHidden=falsesh
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq -r '.items[] | "\(.id)\t\(.title)"' | while IFS=$'\t' read LIST_ID LIST_TITLE; do
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode 'showCompleted=false' \
--data-urlencode 'maxResults=100' \
| jq --arg list "$LIST_TITLE" '.items[]? | {list: $list, title, due, status, notes}'
done | jq -s '. | sort_by(.due // "9999")'showCompleted=falseshowCompleted=true&showHidden=falsePending tasks in one specific list, sorted by due date
单个指定列表中的未完成任务,按截止日期排序
sh
LIST_ID='MTAxMjM0NTY3OA'
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode 'showCompleted=false' \
--data-urlencode 'maxResults=100' \
| jq '.items // [] | sort_by(.due // "9999") | .[] | {title, due, notes, status, position}'positionduesh
LIST_ID='MTAxMjM0NTY3OA'
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode 'showCompleted=false' \
--data-urlencode 'maxResults=100' \
| jq '.items // [] | sort_by(.due // "9999") | .[] | {title, due, notes, status, position}'positiondueTasks due today
今日到期的任务
sh
TODAY=$(date -u +%Y-%m-%d)
TOMORROW=$(date -u -d "+1 day" +%Y-%m-%d 2>/dev/null \
|| date -u -v+1d +%Y-%m-%d)
TODAY_START="${TODAY}T00:00:00.000Z"
TOMORROW_START="${TOMORROW}T00:00:00.000Z"
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq -r '.items[] | "\(.id)\t\(.title)"' | while IFS=$'\t' read LIST_ID LIST_TITLE; do
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode "dueMin=$TODAY_START" \
--data-urlencode "dueMax=$TOMORROW_START" \
--data-urlencode 'showCompleted=false' \
| jq --arg list "$LIST_TITLE" '.items[]? | {list: $list, title, due, notes}'
done | jq -sdueMindueMaxduesh
TODAY=$(date -u +%Y-%m-%d)
TOMORROW=$(date -u -d "+1 day" +%Y-%m-%d 2>/dev/null \
|| date -u -v+1d +%Y-%m-%d)
TODAY_START="${TODAY}T00:00:00.000Z"
TOMORROW_START="${TOMORROW}T00:00:00.000Z"
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq -r '.items[] | "\(.id)\t\(.title)"' | while IFS=$'\t' read LIST_ID LIST_TITLE; do
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode "dueMin=$TODAY_START" \
--data-urlencode "dueMax=$TOMORROW_START" \
--data-urlencode 'showCompleted=false' \
| jq --arg list "$LIST_TITLE" '.items[]? | {list: $list, title, due, notes}'
done | jq -sdueMindueMaxdueOverdue tasks (everything still pending with a due date in the past)
逾期任务(所有未完成且截止日期已过的任务)
sh
NOW=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq -r '.items[] | "\(.id)\t\(.title)"' | while IFS=$'\t' read LIST_ID LIST_TITLE; do
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode "dueMax=$NOW" \
--data-urlencode 'showCompleted=false' \
| jq --arg list "$LIST_TITLE" '.items[]? | {list: $list, title, due, daysOverdue: (((now * 1000) - (.due | sub("Z"; "+00:00") | fromdateiso8601 * 1000)) / 86400000 | floor)}'
done | jq -ssh
NOW=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq -r '.items[] | "\(.id)\t\(.title)"' | while IFS=$'\t' read LIST_ID LIST_TITLE; do
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode "dueMax=$NOW" \
--data-urlencode 'showCompleted=false' \
| jq --arg list "$LIST_TITLE" '.items[]? | {list: $list, title, due, daysOverdue: (((now * 1000) - (.due | sub("Z"; "+00:00") | fromdateiso8601 * 1000)) / 86400000 | floor)}'
done | jq -sRecently completed tasks (this week, for a recap)
近期已完成任务(本周,用于回顾)
sh
ONE_WEEK_AGO=$(date -u -d "-7 days" +%Y-%m-%dT%H:%M:%S.000Z 2>/dev/null \
|| date -u -v-7d +%Y-%m-%dT%H:%M:%S.000Z)
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq -r '.items[] | "\(.id)\t\(.title)"' | while IFS=$'\t' read LIST_ID LIST_TITLE; do
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode 'showCompleted=true' \
--data-urlencode 'showHidden=true' \
--data-urlencode "completedMin=$ONE_WEEK_AGO" \
| jq --arg list "$LIST_TITLE" '.items[]? | select(.status=="completed") | {list: $list, title, completed}'
done | jq -s '. | sort_by(.completed)'completedMincompletedMaxdueMinMaxshowCompleted=trueshowHidden=truesh
ONE_WEEK_AGO=$(date -u -d "-7 days" +%Y-%m-%dT%H:%M:%S.000Z 2>/dev/null \
|| date -u -v-7d +%Y-%m-%dT%H:%M:%S.000Z)
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq -r '.items[] | "\(.id)\t\(.title)"' | while IFS=$'\t' read LIST_ID LIST_TITLE; do
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode 'showCompleted=true' \
--data-urlencode 'showHidden=true' \
--data-urlencode "completedMin=$ONE_WEEK_AGO" \
| jq --arg list "$LIST_TITLE" '.items[]? | select(.status=="completed") | {list: $list, title, completed}'
done | jq -s '. | sort_by(.completed)'completedMincompletedMaxdueMinMaxshowCompleted=trueshowHidden=trueGet one task's details
获取单个任务的详细信息
sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID" \
| jq '{title, due, status, notes, completed, position, links: .links}'linkssh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID" \
| jq '{title, due, status, notes, completed, position, links: .links}'linksPagination
分页处理
maxResultsnextPageTokensh
LIST_ID='MTAxMjM0NTY3OA'
PAGE_TOKEN=''
while : ; do
RESP=$(curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode 'maxResults=100' \
--data-urlencode 'showCompleted=false' \
${PAGE_TOKEN:+--data-urlencode "pageToken=$PAGE_TOKEN"})
echo "$RESP" | jq -c '.items[]?'
PAGE_TOKEN=$(echo "$RESP" | jq -r '.nextPageToken // empty')
[ -z "$PAGE_TOKEN" ] && break
donemaxResultsnextPageTokensh
LIST_ID='MTAxMjM0NTY3OA'
PAGE_TOKEN=''
while : ; do
RESP=$(curl -sS -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--get "https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
--data-urlencode 'maxResults=100' \
--data-urlencode 'showCompleted=false' \
${PAGE_TOKEN:+--data-urlencode "pageToken=$PAGE_TOKEN"})
echo "$RESP" | jq -c '.items[]?'
PAGE_TOKEN=$(echo "$RESP" | jq -r '.nextPageToken // empty')
[ -z "$PAGE_TOKEN" ] && break
doneWrite recipes
写入操作示例
These all need the broader scope. If the user only granted
you'll get — surface
that and ask them to re-install with the read+write box checked.
taskstasks.readonly403 insufficientPermissions这些操作都需要更广泛的权限。如果用户仅授予了权限,会返回——需向用户展示该错误,并提示他们重新安装连接器并勾选读写权限选项。
taskstasks.readonly403 insufficientPermissionsAdd a new task
添加新任务
sh
LIST_ID='MTAxMjM0NTY3OA'
curl -sS -X POST -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"title":"Draft Q2 plan","notes":"Outline + risks + asks.","due":"2026-05-15T00:00:00.000Z"}' \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
| jq '{id, title, due, status}'Google stores as midnight UTC of the chosen day — the time of
day is ignored in the UI. To insert at the very top of the list,
add (no value) to the URL.
due?previous=sh
LIST_ID='MTAxMjM0NTY3OA'
curl -sS -X POST -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"title":"Draft Q2 plan","notes":"Outline + risks + asks.","due":"2026-05-15T00:00:00.000Z"}' \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
| jq '{id, title, due, status}'Google会将存储为所选日期的UTC午夜时间——UI中会忽略具体时间。要将任务插入到列表顶部,需在URL后添加(无值)。
due?previous=Bulk add three tasks under user confirmation
批量添加三个任务(需用户确认)
sh
LIST_ID='MTAxMjM0NTY3OA'
DUE='2026-05-12T00:00:00.000Z'
for T in 'Reply to Alice' 'Review PR #404' 'Send meeting recap'; do
curl -sS -X POST -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data "{\"title\":$(jq -nr --arg t "$T" '$t'),\"due\":\"$DUE\"}" \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
| jq -c '{id, title, due}'
doneAlways list the titles you're about to create and ask for the user's
go-ahead before running this loop — there is no atomic batch endpoint.
sh
LIST_ID='MTAxMjM0NTY3OA'
DUE='2026-05-12T00:00:00.000Z'
for T in 'Reply to Alice' 'Review PR #404' 'Send meeting recap'; do
curl -sS -X POST -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data "{\"title\":$(jq -nr --arg t "$T" '$t'),\"due\":\"$DUE\"}" \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks" \
| jq -c '{id, title, due}'
done在执行此循环前,务必列出即将创建的任务标题并获得用户的同意——目前没有原子批量操作的端点。
Mark a task complete
标记任务为已完成
sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
NOW=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)
curl -sS -X PATCH -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data "{\"status\":\"completed\",\"completed\":\"$NOW\"}" \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID" \
| jq '{id, title, status, completed}'Reverse with .
{"status":"needsAction","completed":null}sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
NOW=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)
curl -sS -X PATCH -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data "{\"status\":\"completed\",\"completed\":\"$NOW\"}" \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID" \
| jq '{id, title, status, completed}'如需撤销,使用。
{"status":"needsAction","completed":null}Edit a task's title / notes / due date
编辑任务的标题/备注/截止日期
sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
curl -sS -X PATCH -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"title":"Draft Q2 plan (rev2)","notes":"Cover risks + asks + budget.","due":"2026-05-20T00:00:00.000Z"}' \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID" \
| jq '{id, title, due, notes}'sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
curl -sS -X PATCH -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"title":"Draft Q2 plan (rev2)","notes":"Cover risks + asks + budget.","due":"2026-05-20T00:00:00.000Z"}' \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID" \
| jq '{id, title, due, notes}'Delete a task
删除任务
sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
curl -sS -X DELETE -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID" \
-o /dev/null -w 'HTTP %{http_code}\n'204sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
curl -sS -X DELETE -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID" \
-o /dev/null -w 'HTTP %{http_code}\n'204Re-order: move a task to a position
重新排序:将任务移动到指定位置
sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
PREV='dGFza0lkUHJldg' # task id this one should appear AFTER; omit to move to top
curl -sS -X POST -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--data '' \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID/move?previous=$PREV" \
| jq '{id, title, parent, position}'Use instead of to nest a task under
another task as a sub-task.
?parent=...?previous=...sh
LIST_ID='MTAxMjM0NTY3OA'
TASK_ID='dGFza0lkRXhhbXBsZQ'
PREV='dGFza0lkUHJldg' # 此任务应排在该任务之后;留空则移动到顶部
curl -sS -X POST -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
--data '' \
"https://tasks.googleapis.com/tasks/v1/lists/$LIST_ID/tasks/$TASK_ID/move?previous=$PREV" \
| jq '{id, title, parent, position}'使用替代可将任务嵌套为另一个任务的子任务。
?parent=...?previous=...Create a brand-new task list
创建新的任务列表
sh
curl -sS -X POST -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"title":"Q2 follow-ups"}' \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq '{id, title}'sh
curl -sS -X POST -H "Authorization: Bearer $GOOGLE_TASKS_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"title":"Q2 follow-ups"}' \
"https://tasks.googleapis.com/tasks/v1/users/@me/lists" \
| jq '{id, title}'Common error codes
常见错误码
| HTTP | meaning | what to tell the user |
|---|---|---|
| token expired / revoked | "Reconnect the Google Tasks connector on the Connections page." |
| write scope missing | "This action needs the Tasks read+write scope, but only |
| wrong list / task id | re-list with |
| quota / throttling | back off ~5s, then retry once. |
Never log or echo — treat it as a secret.
$GOOGLE_TASKS_TOKEN| HTTP | 含义 | 提示用户的内容 |
|---|---|---|
| 令牌过期/已撤销 | "请在连接页面重新连接Google Tasks连接器。" |
| 缺少写入权限 | "此操作需要Tasks读写权限,但当前仅授予了 |
| 任务列表/任务ID错误 | 重新执行 |
| 配额超限/限流 | 等待约5秒后重试一次。 |
切勿记录或回显——需将其视为机密信息。
$GOOGLE_TASKS_TOKEN