通过托管OAuth集成Google Slides API,创建演示文稿、添加幻灯片、插入内容并管理幻灯片格式。当用户想要创建演示文稿时使用此技能。
Google 幻灯片是一项面向实际任务的技能,主要用于使用管理 OAuth 认证的 Google 幻灯片 API;创建和管理演示文稿, 添加幻灯片, 插入文本和图像, 以及控制格式化;
使用时应结合输入条件选择合适的执行方式,核对必要参数、依赖环境与输出内容,并按原始要求处理异常情况。该技能适合需要稳定复用相关能力的场景,可作为自动化工作流的一部分,也便于后续检查、调整和扩展。从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。
实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
通过托管的 OAuth 认证访问 Google Slides API。创建和管理演示文稿、添加幻灯片、插入文本与图片,并控制格式设置。
# 创建一个新的演示文稿
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'title': 'My Presentation'}).encode()
req = urllib.request.Request('https://api.maton.ai/google-slides/v1/presentations', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
https://api.maton.ai/google-slides/{native-api-path}
Maton 将请求代理至 slides.googleapis.com,并自动注入您的 OAuth 令牌。
所有请求均需在 Authorization 请求头中提供 Maton API 密钥:
Authorization: Bearer $MATON_API_KEY
环境变量:将您的 API 密钥设为 MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
在 https://api.maton.ai 管理您的 Google OAuth 连接。
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections?app=google-slides&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'google-slides'}).encode()
req = urllib.request.Request('https://api.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
响应示例:
{
"connection": {
"connection_id": "{connection_id}",
"status": "ACTIVE",
"creation_time": "2025-12-08T07:20:53.488460Z",
"last_updated_time": "2026-01-31T20:03:32.593153Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "google-slides",
"metadata": {}
}
}
在浏览器中打开返回的 url 以完成 OAuth 授权流程。
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
若您拥有多个 Google Slides 连接,请使用 Maton-Connection 请求头指定所用连接:
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'title': 'My Presentation'}).encode()
req = urllib.request.Request('https://api.maton.ai/google-slides/v1/presentations', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
req.add_header('Maton-Connection', '{connection_id}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
当存在多个连接时,务必始终包含该请求头,以确保请求被路由至目标账户。
POST /google-slides/v1/presentations
Content-Type: application/json
{
"title": "My Presentation"
}
GET /google-slides/v1/presentations/{presentationId}
GET /google-slides/v1/presentations/{presentationId}/pages/{pageId}
GET /google-slides/v1/presentations/{presentationId}/pages/{pageId}/thumbnail
自定义尺寸:
GET /google-slides/v1/presentations/{presentationId}/pages/{pageId}/thumbnail?thumbnailProperties.mimeType=PNG&thumbnailProperties.thumbnailSize=LARGE
大多数修改操作均通过 batchUpdate 接口完成。该接口接收一个请求数组,并以原子方式应用全部请求。
POST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [...]
}
POST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [
{
"createSlide": {
"objectId": "slide_001",
"slideLayoutReference": {
"predefinedLayout": "TITLE_AND_BODY"
}
}
}
]
}
可用的预定义版式:
BLANKTITLETITLE_AND_BODYTITLE_AND_TWO_COLUMNSTITLE_ONLYSECTION_HEADERONE_COLUMN_TEXTMAIN_POINTBIG_NUMBERPOST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [
{
"insertText": {
"objectId": "{shapeId}",
"text": "Hello, World!",
"insertionIndex": 0
}
}
]
}
POST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [
{
"deleteText": {
"objectId": "{shapeId}",
"textRange": {
"type": "ALL"
}
}
}
]
}
POST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [
{
"createShape": {
"objectId": "shape_001",
"shapeType": "TEXT_BOX",
"elementProperties": {
"pageObjectId": "{slideId}",
"size": {
"width": {"magnitude": 300, "unit": "PT"},
"height": {"magnitude": 100, "unit": "PT"}
},
"transform": {
"scaleX": 1,
"scaleY": 1,
"translateX": 100,
"translateY": 100,
"unit": "PT"
}
}
}
}
]
}
POST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [
{
"createImage": {
"objectId": "image_001",
"url": "https://example.com/image.png",
"elementProperties": {
"pageObjectId": "{slideId}",
"size": {
"width": {"magnitude": 200, "unit": "PT"},
"height": {"magnitude": 200, "unit": "PT"}
},
"transform": {
"scaleX": 1,
"scaleY": 1,
"translateX": 200,
"translateY": 200,
"unit": "PT"
}
}
}
}
]
}
POST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [
{
"deleteObject": {
"objectId": "{objectId}"
}
}
]
}
POST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [
{
"updateTextStyle": {
"objectId": "{shapeId}",
"textRange": {
"type": "ALL"
},
"style": {
"bold": true,
"fontSize": {"magnitude": 24, "unit": "PT"},
"foregroundColor": {
"opaqueColor": {
"rgbColor": {"red": 0.2, "green": 0.4, "blue": 0.8}
}
}
},
"fields": "bold,fontSize,foregroundColor"
}
}
]
}
POST /google-slides/v1/presentations/{presentationId}:batchUpdate
Content-Type: application/json
{
"requests": [
{
"replaceAllText": {
"containsText": {
"text": "{{placeholder}}",
"matchCase": true
},
"replaceText": "Actual Value"
}
}
]
}
// 创建一个演示文稿
const response = await fetch(
'https://api.maton.ai/google-slides/v1/presentations',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
},
body: JSON.stringify({ title: 'My Presentation' })
}
);
const presentation = await response.json();
const presentationId = presentation.presentationId;
// 添加一张幻灯片
await fetch(
`https://api.maton.ai/google-slides/v1/presentations/${presentationId}:batchUpdate`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
},
body: JSON.stringify({
requests: [
{
createSlide: {
slideLayoutReference: { predefinedLayout: 'TITLE_AND_BODY' }
}
}
]
})
}
);
import os
import requests
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'
}
# 创建一个演示文稿
response = requests.post(
'https://api.maton.ai/google-slides/v1/presentations',
headers=headers,
json={'title': 'My Presentation'}
)
presentation = response.json()
presentation_id = presentation['presentationId']
# 添加一张幻灯片
requests.post(
f'https://api.maton.ai/google-slides/v1/presentations/{presentation_id}:batchUpdate',
headers=headers,
json={
'requests': [
{
'createSlide': {
'slideLayoutReference': {'predefinedLayout': 'TITLE_AND_BODY'}
}
}
]
}
)
batchUpdatebatchUpdate 中的多个请求将被原子化执行replaceAllText 实现基于模板的演示文稿生成curl -g 参数禁用 glob 解析jq 或其他命令时,在某些 shell 环境下环境变量(如 $MATON_API_KEY)可能无法正确展开,从而导致“Invalid API key”错误| 状态码 | 含义 |
|---|---|
| 400 | 缺少 Google Slides 连接 |
| 401 | Maton API 密钥无效或缺失 |
| 404 | 未找到演示文稿 |
| 429 | 请求频率受限(每个账户每秒最多 10 次请求) |
| 4xx/5xx | 来自 Google Slides API 的透传错误 |
MATON_API_KEY 环境变量是否已设置:echo $MATON_API_KEY
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
google-slides 开头。例如:https://api.maton.ai/google-slides/v1/presentationshttps://api.maton.ai/slides/v1/presentations