返回顶部
g

google-docs谷歌文档

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.5
安全检测
已通过
6,707
下载量
免费
免费
8
收藏
概述
安装方式
版本历史

google-docs

Google Docs

通过托管OAuth认证访问Google Docs API。创建文档、插入和格式化文本,以及管理文档内容。

快速开始

bash

获取文档


python < import urllib.request, os, json
req = urllib.request.Request(https://gateway.maton.ai/google-docs/v1/documents/{documentId})
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

基础URL

https://gateway.maton.ai/google-docs/{native-api-path}

将{native-api-path}替换为实际的Google Docs API端点路径。网关将请求代理到docs.googleapis.com,并自动注入您的OAuth令牌。

认证

所有请求都需要在Authorization头中携带Maton API密钥:

Authorization: Bearer $MATONAPIKEY

环境变量: 将您的API密钥设置为MATONAPIKEY:

bash
export MATONAPIKEY=YOURAPIKEY

获取您的API密钥

  1. 1. 在maton.ai登录或创建账户
  2. 前往maton.ai/settings
  3. 复制您的API密钥

连接管理

在https://ctrl.maton.ai管理您的Google OAuth连接。

列出连接

bash
python < import urllib.request, os, json
req = urllib.request.Request(https://ctrl.maton.ai/connections?app=google-docs&status=ACTIVE)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

创建连接

bash
python < import urllib.request, os, json
data = json.dumps({app: google-docs}).encode()
req = urllib.request.Request(https://ctrl.maton.ai/connections, data=data, method=POST)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Content-Type, application/json)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

获取连接

bash
python < import urllib.request, os, json
req = urllib.request.Request(https://ctrl.maton.ai/connections/{connection_id})
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

响应:
json
{
connection: {
connection_id: 21fd90f9-5935-43cd-b6c8-bde9d915ca80,
status: ACTIVE,
creation_time: 2025-12-08T07:20:53.488460Z,
lastupdatedtime: 2026-01-31T20:03:32.593153Z,
url: https://connect.maton.ai/?session_token=...,
app: google-docs,
metadata: {}
}
}

在浏览器中打开返回的url以完成OAuth授权。

删除连接

bash
python < import urllib.request, os, json
req = urllib.request.Request(https://ctrl.maton.ai/connections/{connection_id}, method=DELETE)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

指定连接

如果您有多个Google Docs连接,请使用Maton-Connection头指定要使用的连接:

bash
python < import urllib.request, os, json
req = urllib.request.Request(https://gateway.maton.ai/google-docs/v1/documents/{documentId})
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Maton-Connection, 21fd90f9-5935-43cd-b6c8-bde9d915ca80)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

如果省略,网关将使用默认(最早创建的)活动连接。

API参考

获取文档

bash
GET /google-docs/v1/documents/{documentId}

创建文档

bash
POST /google-docs/v1/documents
Content-Type: application/json

{
title: 新文档
}

批量更新文档

bash
POST /google-docs/v1/documents/{documentId}:batchUpdate
Content-Type: application/json

{
requests: [
{
insertText: {
location: {index: 1},
text: 你好,世界!
}
}
]
}

常用batchUpdate请求

插入文本

json
{
insertText: {
location: {index: 1},
text: 要插入的文本
}
}

删除内容

json
{
deleteContentRange: {
range: {
startIndex: 1,
endIndex: 10
}
}
}

替换所有文本

json
{
replaceAllText: {
containsText: {
text: {{占位符}},
matchCase: true
},
replaceText: 替换值
}
}

插入表格

json
{
insertTable: {
location: {index: 1},
rows: 3,
columns: 3
}
}

更新文本样式

json
{
updateTextStyle: {
range: {
startIndex: 1,
endIndex: 10
},
textStyle: {
bold: true,
fontSize: {magnitude: 14, unit: PT}
},
fields: bold,fontSize
}
}

插入分页符

json
{
insertPageBreak: {
location: {index: 1}
}
}

代码示例

JavaScript

javascript
// 创建文档
const response = await fetch(
https://gateway.maton.ai/google-docs/v1/documents,
{
method: POST,
headers: {
Content-Type: application/json,
Authorization: Bearer ${process.env.MATONAPIKEY}
},
body: JSON.stringify({ title: 新文档 })
}
);

// 插入文本
await fetch(
https://gateway.maton.ai/google-docs/v1/documents/${docId}:batchUpdate,
{
method: POST,
headers: {
Content-Type: application/json,
Authorization: Bearer ${process.env.MATONAPIKEY}
},
body: JSON.stringify({
requests: [{ insertText: { location: { index: 1 }, text: 你好! } }]
})
}
);

Python

python
import os
import requests

创建文档

response = requests.post( https://gateway.maton.ai/google-docs/v1/documents, headers={Authorization: fBearer {os.environ[MATONAPIKEY]}}, json={title: 新文档} )

注意事项

  • - 索引位置从1开始(文档从索引1开始)
  • 使用endOfSegmentLocation在末尾追加内容
  • batchUpdate中的多个请求会原子性应用
  • 先获取文档以找到更新的正确索引
  • 样式更新中的fields参数使用字段掩码语法
  • 重要提示:使用curl命令时,当URL包含括号(fields[]、sort[]、records[])时,请使用curl -g禁用通配符解析
  • 重要提示:将curl输出通过管道传递给jq或其他命令时,环境变量(如$MATONAPIKEY)在某些shell环境中可能无法正确展开。管道传递时可能会收到Invalid API key错误。

错误处理

状态码含义
400缺少Google Docs连接
401
无效或缺少Maton API密钥 | | 429 | 请求频率限制(每个账户10次/秒) | | 4xx/5xx | 来自Google Docs API的透传错误 |

故障排除:API密钥问题

  1. 1. 检查MATONAPIKEY环境变量是否已设置:

bash
echo $MATONAPIKEY

  1. 2. 通过列出连接验证API密钥是否有效:

bash
python < import urllib

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 google-docs-1776058384 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 google-docs-1776058384 技能

通过命令行安装

skillhub install google-docs-1776058384

下载

⬇ 下载 google-docs v1.0.5(免费)

文件大小: 4.06 KB | 发布时间: 2026-4-15 12:56

v1.0.5 最新 2026-4-15 12:56
- Added a new `clawdbot` metadata field with an emoji and required environment variable `MATON_API_KEY`.
- No other functionality or documentation changes.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部