|
通过托管OAuth认证访问Google Docs API。创建文档、插入和格式化文本,以及管理文档内容。
bash
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
在https://ctrl.maton.ai管理您的Google OAuth连接。
bash
python <
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 <
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 <
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 <
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 <
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
如果省略,网关将使用默认(最早创建的)活动连接。
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: 你好,世界!
}
}
]
}
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
// 创建文档
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
import os
import requests
| 状态码 | 含义 |
|---|---|
| 400 | 缺少Google Docs连接 |
| 401 |
bash
echo $MATONAPIKEY
bash
python <
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 google-docs-1776058384 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 google-docs-1776058384 技能
skillhub install google-docs-1776058384
文件大小: 4.06 KB | 发布时间: 2026-4-15 12:56