google-docs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDrive Google Docs via . The user's OAuth bearer token is in
; every call needs . Base URL: . The
token carries (+ identity); writes need .
curl + jq$GOOGLE_DOCS_TOKENAuthorization: Bearer $GOOGLE_DOCS_TOKENhttps://docs.googleapis.com/v1/documentsdocuments.readonlydocumentsFailures are — show verbatim. =
re-install. on a write = read-only scope.
{"error":{"code","message","status"}}401403 PERMISSION_DENIEDThe doc id is the segment of the URL.
…/document/d/<ID>/editbash
D="https://docs.googleapis.com/v1/documents"; AUTH="Authorization: Bearer $GOOGLE_DOCS_TOKEN"通过操作Google Docs。用户的OAuth承载令牌存储在中;每次调用都需要带上。基础URL:。令牌包含(+身份验证)权限;写入操作需要权限。
curl + jq$GOOGLE_DOCS_TOKENAuthorization: Bearer $GOOGLE_DOCS_TOKENhttps://docs.googleapis.com/v1/documentsdocuments.readonlydocuments错误返回格式为——需原样展示。错误表示需要重新安装授权。写入时出现错误表示当前为只读权限范围。
{"error":{"code","message","status"}}401403 PERMISSION_DENIED文档ID是URL中部分的<ID>。
…/document/d/<ID>/editbash
D="https://docs.googleapis.com/v1/documents"; AUTH="Authorization: Bearer $GOOGLE_DOCS_TOKEN"Read the document. The body is a tree of structural elements; pull plain text:
Read the document. The body is a tree of structural elements; pull plain text:
curl -sS -H "$AUTH" "$D/DOC_ID"
| jq -r '.title, ([.body.content[]?.paragraph?.elements[]?.textRun?.content] | join(""))'
| jq -r '.title, ([.body.content[]?.paragraph?.elements[]?.textRun?.content] | join(""))'
undefinedcurl -sS -H "$AUTH" "$D/DOC_ID"
| jq -r '.title, ([.body.content[]?.paragraph?.elements[]?.textRun?.content] | join(""))'
| jq -r '.title, ([.body.content[]?.paragraph?.elements[]?.textRun?.content] | join(""))'
undefinedCreate & edit
创建与编辑
bash
undefinedbash
undefinedCreate an empty doc
Create an empty doc
curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json"
-d '{"title":"Meeting notes 2026-06-21"}' "$D" | jq '{documentId, title}'
-d '{"title":"Meeting notes 2026-06-21"}' "$D" | jq '{documentId, title}'
curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json"
-d '{"title":"Meeting notes 2026-06-21"}' "$D" | jq '{documentId, title}'
-d '{"title":"Meeting notes 2026-06-21"}' "$D" | jq '{documentId, title}'
Insert text at the start (index 1) via batchUpdate (confirm first)
Insert text at the start (index 1) via batchUpdate (confirm first)
curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json"
-d '{"requests":[{"insertText":{"location":{"index":1},"text":"Hello\n"}}]}'
"$D/DOC_ID:batchUpdate" | jq '.documentId'
-d '{"requests":[{"insertText":{"location":{"index":1},"text":"Hello\n"}}]}'
"$D/DOC_ID:batchUpdate" | jq '.documentId'
curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json"
-d '{"requests":[{"insertText":{"location":{"index":1},"text":"Hello\n"}}]}'
"$D/DOC_ID:batchUpdate" | jq '.documentId'
-d '{"requests":[{"insertText":{"location":{"index":1},"text":"Hello\n"}}]}'
"$D/DOC_ID:batchUpdate" | jq '.documentId'
Replace all occurrences of a placeholder
Replace all occurrences of a placeholder
curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json"
-d '{"requests":[{"replaceAllText":{"containsText":{"text":"{{name}}","matchCase":true},"replaceText":"Alex"}}]}'
"$D/DOC_ID:batchUpdate" | jq '.replies'
-d '{"requests":[{"replaceAllText":{"containsText":{"text":"{{name}}","matchCase":true},"replaceText":"Alex"}}]}'
"$D/DOC_ID:batchUpdate" | jq '.replies'
undefinedcurl -sS -X POST -H "$AUTH" -H "Content-Type: application/json"
-d '{"requests":[{"replaceAllText":{"containsText":{"text":"{{name}}","matchCase":true},"replaceText":"Alex"}}]}'
"$D/DOC_ID:batchUpdate" | jq '.replies'
-d '{"requests":[{"replaceAllText":{"containsText":{"text":"{{name}}","matchCase":true},"replaceText":"Alex"}}]}'
"$D/DOC_ID:batchUpdate" | jq '.replies'
undefinedGotchas
注意事项
- The document model is index-based: text edits target character indices, and every insert shifts later indices — for multiple inserts, apply them back-to-front or recompute indices between calls.
- To get clean Markdown/plain text, walk (the jq above). Tables / lists need deeper traversal.
body.content[].paragraph.elements[] .textRun.content - Creating a doc puts it in the user's Drive root; use the skill to move/share it.
google-drive
- 文档模型是基于索引的:文本编辑以字符索引为目标,每次插入操作都会改变后续索引——如果要执行多次插入,需从后往前操作,或者在每次调用之间重新计算索引。
- 若要获取整洁的Markdown/纯文本,需遍历(如上述jq命令所示)。表格/列表需要更深入的遍历。
body.content[].paragraph.elements[] .textRun.content - 创建的文档会存放在用户的Drive根目录中;可使用技能来移动/共享文档。
google-drive