360 Secure SkillHub
360 安全技能中心

Google Docs Writer

该 Skill 通过 Python 脚本调用 Google Docs API,对指定文档执行读取、整体写入、追加、清空和查找替换;写入时可将 Markdown 标题转换为 Google Docs 原生标题,并复用 gog 在 GNOME keyring 中保存的 OAuth 凭据。

agenttrust
agenttrust
热度 31.58
最近更新 2026-05-03 02:31:52
分类:自动化依赖:代码执行 / 第三方 API / 读写文件应用场景:自动化脚本 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add google-docs-writer
Metadata
name
google-docs-writer
description
Read, write, append, clear, and find-replace content in Google Docs via the Docs API. Use when gog CLI is insufficient (gog only supports read-only doc operations). Requires gog OAuth to be configured (gog auth add). Supports auto-formatting of markdown headers into native Google Docs headings.

Google Docs Writer

Extends gog with write operations for Google Docs. Uses the same OAuth credentials gog stores in the GNOME keyring.

Prerequisites

  • gog auth add completed (OAuth token in keyring)
  • secretstorage Python package (pre-installed on most Linux desktops)
  • Doc must be owned by or shared as Editor with the authenticated account

Commands

Script: scripts/gdocs.py

# Read doc content as plain text
python3 scripts/gdocs.py read <docId>

# Replace entire doc with content from file
python3 scripts/gdocs.py write <docId> <textFile>

# Append content from file to end of doc
python3 scripts/gdocs.py append <docId> <textFile>

# Clear all doc content
python3 scripts/gdocs.py clear <docId>

# Find and replace text
python3 scripts/gdocs.py replace <docId> "find this" "replace with"

Formatting

The write command auto-converts markdown headers to Google Docs headings:

  • # Heading → Heading 1
  • ## Heading → Heading 2
  • ### Heading → Heading 3

Header markers (#) are stripped from the final doc.

Workflow

  1. Write content to a temp file (markdown-formatted for best results)
  2. Use write (replace all) or append (add to end)
  3. Use read to verify

For creating new docs, use gog docs create <title> first, then write content with this skill.

Token Caching

Access tokens are cached at /tmp/.gdocs_access_token for ~50 minutes. No manual token management needed.

Error: 403 Permission Denied

The authenticated account (gabagent00@gmail.com) needs Editor access to the doc. Shared docs default to Viewer — the doc owner must grant edit permission.