使用说明
谷歌幻灯片MCP服务器
一个HTTP流式MCP(模型上下文协议)服务器,为AI助手提供与Google幻灯片演示文稿交互的工具。
概述
此MCP服务器使AI助手能够:
- 阅读并分析Google幻灯片演示文稿
- 创建、修改和管理幻灯片
- 处理文本、图像、形状、表格和视频
- 应用主题、过渡和动画
- 管理评论和演讲者笔记
- 翻译演示文稿
- 导出为PDF和其他格式
特性
核心能力
- 40+MCP工具:用于演示文稿操作的全套工具
- 读取操作:加载演示文稿、列出幻灯片、搜索文本、描述对象
- 写入操作:创建幻灯片、添加文本/图像/视频、修改形状、应用主题
- 批量操作:在单个API调用中执行多个操作
- 翻译:通过Google Translate API将演示文稿翻译成100多种语言
安全性和可靠性
- OAuth2身份验证:通过Google帐户进行安全的用户授权
- API密钥管理:具有Firestore存储的基于UUID的API密钥
- 权限验证:在修改之前验证写入权限
- 速率限制:具有可配置限制的令牌桶算法
- 重试逻辑:瞬态故障时具有抖动的指数回退
- 缓存:用于令牌、权限和文档结构的内存LRU缓存
部署和运营
- 云原生:专为Google Cloud Run部署而设计
- 基础设施即代码:完整的地形配置
- CI/CD就绪:Cloud Build与自动化部署的集成
- 健康监测:负载平衡器的运行状况检查端点
- 结构化日志记录:带请求跟踪的JSON日志记录
建筑
该服务器设计为在Google Cloud run上运行,并使用:
- HTTP流传输:基于HTTP的JSON-RPC 2.0,采用分块传输编码
- OAuth2身份验证:通过Google OAuth2进行用户授权
- API密钥管理:生成的API密钥存储在Firestore中
- 秘密经理:OAuth2凭据的安全存储
架构图
┌─────────────────────────────────────────────────────────────┐
│ Google Cloud Platform │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Cloud Run │ │
┌──────────────┐ │ │ ┌─────────────────────────────────────────────────────┐│ │
│ AI Client │ │ │ │ Google Slides MCP Server ││ │
│ (Claude, │ HTTPS + API Key │ │ │ ││ │
│ ChatGPT, │────────────────────┼──┼──┤ ┌──────────┐ ┌──────────┐ ┌──────────────────┐ ││ │
│ etc.) │ │ │ │ │ Transport │ │ Auth │ │ Tools │ ││ │
└──────────────┘ │ │ │ │ Layer │ │ Layer │ │ (40+ tools) │ ││ │
│ │ │ └────┬─────┘ └────┬─────┘ └────────┬─────────┘ ││ │
│ │ │ │ │ │ │ ││ │
│ │ │ │ │ ┌──────┴──────┐ │ ││ │
▼ │ │ │ │ │ │ │ ││ │
┌──────────────┐ │ │ │ ┌────▼────┐ │ ┌───────────▼──────┐ │ ││ │
│ User │ OAuth2 Flow │ │ │ │Middleware│ │ │ Permission │ │ ││ │
│ (Browser) │◄───────────────────┼──┼──┤ │(API Key, │ │ │ Checker │ │ ││ │
└──────────────┘ │ │ │ │Rate Limit│ │ └─────────────────┘ │ ││ │
│ │ │ └────┬────┘ │ │ ││ │
│ │ │ │ │ │ ││ │
│ │ │ │ │ ┌────────────────────┘ ││ │
│ │ │ ▼ ▼ ▼ ││ │
│ │ │ ┌──────────────────────┐ ││ │
│ │ │ │ Cache Manager │ ││ │
│ │ │ │ (Tokens, Permissions,│ ││ │
│ │ │ │ Presentations) │ ││ │
│ │ │ └──────────────────────┘ ││ │
│ │ └─────────────────────────────────────────────────────┘│ │
│ └─────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────────┼────────────────────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Firestore │ │ Secret │ │ Cloud │ │
│ │ (API Keys, │ │ Manager │ │ Storage │ │
│ │ Tokens) │ │ (OAuth2) │ │ (Images) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Google APIs │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Slides API │ │ Drive API │ │ Translate API│ │
│ │ │ │ │ │ │ │
│ │ - Get/Update │ │ - Search │ │ - Translate │ │
│ │ - BatchUpdate│ │ - Copy/Export│ │ text │ │
│ │ - Thumbnails │ │ - Permissions│ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
数据流
- 身份验证流程:用户通过OAuth2进行身份验证,接收API密钥
- API请求:AI客户端使用授权头中的API密钥发送MCP请求
- 验证:中间件验证API密钥,检查速率限制,创建令牌源
- 权限检查:工具验证用户是否有权访问演示文稿
- API调用:工具使用用户凭据调用Google API(幻灯片、驱动器、翻译)
- 响应:结果通过分块HTTP响应返回
端点
| 端点 | 方法 | 描述 |
|---|---|---|
/health |
GET | 健康检查端点 |
/mcp/initialize |
POST | MCP协议握手 |
/mcp |
POST | MCP工具调用 |
/auth |
GET | 启动OAuth2流 |
/auth/callback |
GET | OAuth2回调 |
MCP协议
服务器实现MCP(模型上下文协议)规范:
- 协议版本:
2024-11-05 - 传输:采用分块传输编码的HTTP
- 格式:JSON-RPC 2.0
初始化请求示例:
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "my-client",
"version": "1.0.0"
}
}
}
项目结构
google-slides-mcp/
├── cmd/
│ └── google-slides-mcp/ # Main application entry point
├── internal/ # Private application code
│ ├── auth/ # OAuth2 and API key authentication
│ ├── cache/ # Caching layer
│ ├── middleware/ # HTTP middleware
│ ├── permissions/ # Permission verification
│ ├── ratelimit/ # Rate limiting
│ ├── retry/ # Retry logic with backoff
│ ├── tools/ # MCP tool implementations
│ └── transport/ # HTTP transport layer
├── pkg/ # Public library code
├── terraform/ # Infrastructure as Code
├── scripts/ # Utility scripts
├── Makefile # Build automation
├── Dockerfile # Container definition
└── cloudbuild.yaml # CI/CD configuration
入门指南
先决条件
- 转到1.21或更高版本
- 谷歌云平台帐户
- 地形(用于部署)
- Docker(用于容器化)
发展
# Build the project
make build
# Run tests
make test
# Run the server locally
make run
# Format code
make fmt
# Run all checks
make check
码头工人
# Build the Docker image
docker build -t google-slides-mcp .
# Run locally with Docker
docker run -p 8080:8080 google-slides-mcp
# Build with version information
docker build \
--build-arg VERSION=1.0.0 \
--build-arg COMMIT_SHA=$(git rev-parse HEAD) \
--build-arg BUILD_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
-t google-slides-mcp .
Docker镜像使用:
- 多阶段构建,实现最小图像尺寸
- 分散基础映像以实现安全
- 非root用户执行(UID 65532)
部署
该服务器旨在部署在Google Cloud Run上。基础设施由Terraform管理。
先决条件
- 启用计费的GCP项目
gcloud配置了项目访问权限的CLI- Terraform 1.0+已安装
基础设施设置
# 1. Update configuration
# Edit terraform/config.yaml with your GCP project ID
vim terraform/config.yaml
# 2. Initialize and deploy infrastructure
make plan # Preview changes
make deploy # Apply changes
# 3. Add OAuth2 credentials to Secret Manager
# After creating OAuth2 credentials in GCP Console:
gcloud secrets versions add gslides-dev-oauth-client-id --data-file=client_id.txt
gcloud secrets versions add gslides-dev-oauth-client-secret --data-file=client_secret.txt
gcloud secrets versions add gslides-dev-oauth-redirect-uri --data-file=redirect_uri.txt
# 4. Deploy the container image (via CI/CD or manual)
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/gslides-mcp:latest
创建地形资源
| 资源 | 描述 |
|---|---|
| 云运行服务 | 具有自动扩展功能的MCP服务器 |
| Firestore数据库 | API密钥和刷新令牌 |
| 密钥管理器 | OAuth2凭据 |
| 服务帐户 | 云运行和云构建 |
| IAM角色 | 最低权限 |
破坏基础设施
make undeploy # Destroy all resources
身份验证流程
服务器使用OAuth2和Google进行用户身份验证:
流程步骤
- 启动流程:客户电话
GET /auth - 获取授权URL:服务器返回JSON
authorization_url{ "authorization_url": "https://accounts.google.com/o/oauth2/auth?...", "message": "Please visit the authorization URL to complete authentication" } - 使用者同意:用户访问URL并授予以下权限:
- Google幻灯片API(读/写演示文稿)
- Google Drive API(搜索、复制、共享文件)
- 谷歌云翻译API(翻译内容)
- 回调:谷歌重定向到
/auth/callback带有授权码 - 代币交换:服务器交换访问和刷新令牌的代码
- API密钥生成:服务器为API密钥生成UUID
- 存储:存储在Firestore中的API密钥和刷新令牌
- 响应:已将API密钥返回给用户(仅显示一次)
{ "message": "Authentication successful", "api_key": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", "api_key_warning": "Save this API key securely. It will not be shown again.", "has_refresh_token": true } - 后续请求:包括
Authorization: Bearer <api_key>头球
API密钥存储
API密钥存储在Firestore中,具有以下结构:
| 字段 | 类型 | 描述 |
|---|---|---|
api_key |
string | UUID v4格式密钥(文档ID) |
refresh_token |
string | OAuth2刷新令牌,用于API访问 |
user_email |
string | 用户的电子邮件(可选) |
created_at |
timestamp | 密钥生成的时间 |
last_used |
timestamp | 上次使用密钥的时间 |
所需的OAuth2范围
https://www.googleapis.com/auth/presentations-完整幻灯片访问https://www.googleapis.com/auth/drive-完全驱动器访问权限https://www.googleapis.com/auth/cloud-translation-翻译API
安全特性
- 通过加密状态参数进行CSRF保护
- 状态令牌是一次性使用的(在回调后消耗)
- 刷新令牌允许离线访问,无需重新身份验证
- API密钥验证中间件保护所有MCP端点
- TTL令牌缓存可减少Firestore读取
- 上次用于关键活动监控的时间戳跟踪
权限验证
在修改任何演示文稿之前,服务器会验证用户是否具有适当的权限:
- 写入操作:需要
writer或owner角色 - 读取操作:至少需要
viewer或commenter角色
权限检查使用Google Drive API验证文件功能:
- 结果以5分钟的TTL缓存以提高性能
- 权限不足时返回明确的错误消息
权限不足的错误响应示例:
{
"error": "user does not have write permission on this presentation"
}
速率限制
服务器实施全局速率限制以防止滥用:
令牌桶算法
- 每秒可配置的请求限制(默认值:10个请求/秒)
- 处理流量峰值的突发容量(默认值:20个请求)
- 细粒度控制的每端点速率限制
响应头
所有回复均包含费率限制信息:
| 标题 | 描述 |
|---|---|
X-RateLimit-Limit |
允许的最大请求数(突发大小) |
X-RateLimit-Remaining |
当前窗口中的剩余请求 |
X-RateLimit-Reset |
限制重置时的Unix时间戳 |
超出费率限制
当超过速率限制时,服务器返回:
- HTTP状态:
429 Too Many Requests Retry-After标头,还有几秒钟等待- JSON正文:
{ "error": "rate limit exceeded", "retry_after": 1 }
配置
可以针对不同的用例为每个端点配置速率限制:
- 重型作业(如出口):下限
- 读取操作:更高的限制
- 身份验证端点:单独的限制
重试逻辑
服务器实现了具有指数回退的自动重试逻辑,用于处理来自Google API的瞬态故障。
指数退避
- 初始延迟:1秒
- 最大延迟:16秒
- 乘数:2x(每次重试后延迟加倍)
- 最大重试次数:5次
抖动
随机抖动(±20%)应用于延迟,以防止在多个请求同时失败时出现雷鸣般的群体问题。
可重试状态代码
以下HTTP状态代码触发自动重试:
| 状态代码 | 描述 |
|---|---|
| 429 | 请求太多(速率受限) |
| 500 | 内部服务器错误 |
| 502 | 网关故障 |
| 503 | 服务不可用 |
| 504 | 网关超时 |
行为
- 瞬态错误会自动进行重试
- 在重试延迟期间遵守上下文取消
- 不可重试的错误(4xx,429除外)立即失败
- 调试重试行为的详细日志记录
可用的MCP工具
该服务器为Google幻灯片操作提供了全面的工具:
展示管理
get_presentation
加载Google幻灯片演示文稿并返回其完整的结构化内容。
输入:
{
"presentation_id": "abc123xyz",
"include_thumbnails": false
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
include_thumbnails |
boolean | 否 | 包括base64编码的幻灯片缩略图(默认值:false) |
输出:
{
"presentation_id": "abc123xyz",
"title": "My Presentation",
"locale": "en_US",
"slides_count": 5,
"page_size": {
"width": {"magnitude": 720, "unit": "PT"},
"height": {"magnitude": 405, "unit": "PT"}
},
"slides": [
{
"index": 1,
"object_id": "slide-id-1",
"layout_id": "layout-id",
"layout_name": "Title Slide",
"text_content": [
{
"object_id": "text-box-1",
"object_type": "TEXT_BOX",
"text": "Hello World"
}
],
"speaker_notes": "Notes for this slide",
"object_count": 3,
"objects": [
{"object_id": "text-box-1", "object_type": "TEXT_BOX"},
{"object_id": "image-1", "object_type": "IMAGE"}
],
"thumbnail_base64": "..." // Only if include_thumbnails=true
}
],
"masters": [
{"object_id": "master-1", "name": "Default Master"}
],
"layouts": [
{"object_id": "layout-1", "name": "Title Slide", "master_id": "master-1", "layout_type": "TITLE"}
]
}
特征:
- 从幻灯片中提取所有文本内容,包括形状、文本框和表格
- 检索每张幻灯片的演讲者笔记
- 返回完整的演示结构,包括母版和布局
- 可选地包括幻灯片缩略图作为base64编码图像
- 递归处理分组元素
检测到的对象类型:
- 形状:
TEXT_BOX,RECTANGLE,ELLIPSE等等。 - 媒体:
IMAGE,VIDEO - 容器:
TABLE,GROUP - 其他:
LINE,SHEETS_CHART,WORD_ART
错误:
presentation not found-演示文稿ID不存在access denied to presentation-无权访问演示文稿slides API error-其他幻灯片API错误
search_presentations
在Google云端硬盘中搜索Google幻灯片演示文稿。
输入:
{
"query": "quarterly report",
"max_results": 10
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query |
string | 是 | 搜索词或驱动器查询运算符 |
max_results |
integer | 否 | 返回的最大结果数(默认值:10,最大值:100) |
输出:
{
"presentations": [
{
"id": "abc123xyz",
"title": "Q4 Quarterly Report 2024",
"owner": "user@example.com",
"modified_date": "2024-01-15T10:30:00Z",
"thumbnail_url": "https://drive.google.com/thumbnail/..."
}
],
"total_results": 5,
"query": "quarterly report"
}
特征:
- 搜索拥有、共享和共享驱动器演示文稿
- 仅返回谷歌幻灯片文件(不包括文档、表格等)
- 简单查询自动使用全文搜索
- 支持高级Google Drive搜索运营商
高级查询示例:
// Search by name
{"query": "name contains 'Budget'"}
// Search by modification date
{"query": "modifiedTime > '2024-01-01'"}
// Combined search
{"query": "name contains 'Report' and modifiedTime > '2024-01-01'"}
// Search shared files
{"query": "sharedWithMe = true"}
错误:
invalid search query: query is required-提供了空查询access denied-没有搜索驱动器的权限drive API error-其他驱动器API错误
copy_presentation
复制Google幻灯片演示文稿以创建新演示文稿。可用于从模板创建演示文稿。
输入:
{
"source_id": "1abc2def3ghi...",
"new_title": "Q1 2024 Report",
"destination_folder_id": "folder123..."
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
source_id |
string | 是 | 要复制的演示文稿的ID |
new_title |
string | 是 | 新演示文稿的标题 |
destination_folder_id |
string | 否 | 放置副本的文件夹(默认:root) |
输出:
{
"presentation_id": "new-id-123...",
"title": "Q1 2024 Report",
"url": "https://docs.google.com/presentation/d/new-id-123.../edit",
"source_id": "1abc2def3ghi..."
}
特征:
- 创建源演示文稿的精确副本
- 保留所有格式、主题、母版和内容
- 将副本放置在指定文件夹或用户的驱动器根目录中
- 返回直接编辑URL以供立即访问
使用案例:
- 从公司模板创建演示文稿
- 为不同受众复制演示文稿
- 在进行重大更改之前创建备份
错误:
invalid source presentation ID: source_id is required-空源IDinvalid title: new_title is required-空标题source presentation not found-源不存在或无法访问access denied to source presentation-无权复制destination folder not found or inaccessible-文件夹ID无效
export_pdf
将Google幻灯片演示文稿导出为PDF格式。
输入:
{
"presentation_id": "abc123xyz"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 要导出的Google幻灯片演示文稿ID |
输出:
{
"pdf_base64": "JVBERi0xLjQK...",
"page_count": 10,
"file_size": 123456
}
| 字段 | 类型 | 描述 |
|---|---|---|
pdf_base64 |
string | Base64编码的PDF内容 |
page_count |
integer | 在PDF中检测到的页数 |
file_size |
integer | PDF文件大小(字节) |
特征:
- 使用Google Drive API导出功能
- 以base64格式返回PDF,以便通过JSON轻松传输
- 使用PDF结构分析检测页数
- 包括文件大小元数据
使用案例:
- 生成演示文稿的可打印版本
- 创建演示文稿内容的档案
- 与非谷歌用户共享演示文稿
客户端PDF处理:
// Decode and save the PDF
const pdfData = atob(response.pdf_base64);
const blob = new Blob([pdfData], { type: 'application/pdf' });
const url = URL.createObjectURL(blob);
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-无出口许可failed to export presentation-导出操作失败
create_presentation
创建一个新的空白Google幻灯片演示文稿。
输入:
{
"title": "My New Presentation",
"folder_id": "folder-id-optional"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
title |
string | 是 | 新演示文稿的标题 |
folder_id |
string | 否 | 用于放置演示文稿的Google Drive文件夹ID |
输出:
{
"presentation_id": "new-presentation-id",
"title": "My New Presentation",
"url": "https://docs.google.com/presentation/d/new-presentation-id/edit",
"folder_id": "folder-id-optional"
}
| 字段 | 类型 | 描述 |
|---|---|---|
presentation_id |
string | 创建的演示文稿的唯一ID |
title |
string | 演示文稿的标题 |
url |
string | 演示文稿的直接编辑URL |
folder_id |
string | 如果在输入中指定了文件夹ID(否则省略) |
特征:
- 通过幻灯片API创建新的空演示文稿
- 可选择将演示文稿放置在特定文件夹中
- 返回直接编辑URL以供立即访问
使用案例:
- 从头开始创建新的演示文稿
- 以编程方式设置演示结构
- 将演示文稿组织到特定文件夹中
错误:
invalid title for presentation: title is required-空标题access denied-无权创建演示文稿destination folder not found or inaccessible-文件夹ID无效failed to create presentation-创建失败
滑动操作
list_slides
列出演示文稿中的所有幻灯片,包括元数据和摘要统计信息。
输入:
{
"presentation_id": "abc123xyz",
"include_thumbnails": false
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
include_thumbnails |
boolean | 否 | 包括base64编码的幻灯片缩略图(默认值:false) |
输出:
{
"presentation_id": "abc123xyz",
"title": "My Presentation",
"slides": [
{
"index": 1,
"slide_id": "slide-object-id-1",
"title": "Introduction",
"layout_type": "TITLE",
"object_count": 3,
"thumbnail_base64": "..."
},
{
"index": 2,
"slide_id": "slide-object-id-2",
"title": "Overview",
"layout_type": "TITLE_AND_BODY",
"object_count": 5,
"thumbnail_base64": "..."
}
],
"statistics": {
"total_slides": 10,
"slides_with_notes": 5,
"slides_with_videos": 2
}
}
| 字段 | 类型 | 描述 |
|---|---|---|
presentation_id |
string | 演示文稿ID |
title |
string | 演示文稿标题 |
slides |
array | 幻灯片元数据数组 |
slides[].index |
整数 | 1基滑动位置 |
slides[].slide_id |
string | 唯一幻灯片对象ID |
slides[].title |
string | 幻灯片标题(来自title占位符) |
slides[].layout_type |
string | 布局类型(例如,TITLE、TITLE_AND_BODY、BLANK) |
slides[].object_count |
integer | 幻灯片上的页面元素数 |
slides[].thumbnail_base64 |
string | Base64缩略图(仅在请求时) |
statistics.total_slides |
integer | 幻灯片总数 |
statistics.slides_with_notes |
integer | 带演讲者笔记的幻灯片计数 |
statistics.slides_with_videos |
integer | 包含视频的幻灯片计数 |
特征:
- 返回基于1的幻灯片索引,便于人类参考
- 从title或CENTERED_title占位符中提取幻灯片标题
- 从演示文稿布局中检测布局类型
- 统计带有演讲者笔记的幻灯片(非空笔记页面)
- 统计包含视频元素的幻灯片(包括嵌套在组中的幻灯片)
- 通过base64编码提供可选缩略图支持
使用案例:
- 快速了解演示文稿结构
- 按标题浏览大型演示文稿
- 查找具有特定特征的幻灯片(注释、视频)
- 生成目录或幻灯片索引
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-没有访问权限
describe_slide
获取特定幻灯片的详细可读描述,包括所有对象及其位置和内容摘要。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 1
}
或使用幻灯片ID:
{
"presentation_id": "abc123xyz",
"slide_id": "g1234567890"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 其中之一 | 1基幻灯片索引 |
slide_id |
string | 必需 | 唯一幻灯片对象ID |
输出:
{
"presentation_id": "abc123xyz",
"slide_id": "g1234567890",
"slide_index": 1,
"title": "Introduction",
"layout_type": "TITLE_AND_BODY",
"page_size": {
"width": {"magnitude": 720, "unit": "PT"},
"height": {"magnitude": 405, "unit": "PT"}
},
"objects": [
{
"object_id": "title-shape-1",
"object_type": "TEXT_BOX",
"position": {"x": 60.0, "y": 30.0},
"size": {"width": 600.0, "height": 50.0},
"content_summary": "Introduction to the Project",
"z_order": 0
},
{
"object_id": "image-1",
"object_type": "IMAGE",
"position": {"x": 50.0, "y": 100.0},
"size": {"width": 300.0, "height": 200.0},
"content_summary": "Image (external)",
"z_order": 1
},
{
"object_id": "group-1",
"object_type": "GROUP",
"position": {"x": 400.0, "y": 100.0},
"size": {"width": 200.0, "height": 150.0},
"content_summary": "Group (3 items)",
"z_order": 2,
"children": [
{
"object_id": "shape-in-group",
"object_type": "RECTANGLE",
"content_summary": "",
"z_order": 0
}
]
}
],
"layout_description": "Title at top: \"Introduction\". 2 element(s) in center. Contains: 1 group, 1 image, 1 text_box",
"screenshot_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"speaker_notes": "Remember to emphasize the key points here"
}
| 字段 | 类型 | 描述 |
|---|---|---|
presentation_id |
string | 演示文稿ID |
slide_id |
string | 唯一幻灯片对象ID |
slide_index |
整数 | 1基滑动位置 |
title |
string | 幻灯片标题(来自title占位符) |
layout_type |
string | 布局类型(例如,TITLE、TITLE_AND_BODY) |
page_size |
对象 | 幻灯片尺寸 |
objects |
array | 对象描述数组 |
objects[].object_id |
string | 唯一对象标识符 |
objects[].object_type |
string | 对象类型(TEXT_BOX、IMAGE等) |
objects[].position |
对象 | 点中的X、Y位置 |
objects[].size |
object | 宽度、高度(以点为单位) |
objects[].content_summary |
string | 内容摘要(最多100个字符) |
objects[].z_order |
integer | 堆叠顺序(0=向后) |
objects[].children |
array | 子对象(用于组) |
layout_description |
string | 人类可读的布局描述 |
screenshot_base64 |
string | 幻灯片的Base64 PNG截图 |
speaker_notes |
string | 演讲者笔记内容 |
特征:
- 接受幻灯片索引(基于1)或幻灯片ID以获得灵活性
- 返回位置和大小(以点为单位)(从EMU转换而来)
- 为AI上下文生成人类可读的布局描述
- 包括屏幕截图以供视觉参考
- 递归地描述分组元素
- 内容摘要截断为100个字符
内容摘要类型:
- 文本形状:文本内容的前100个字符
- 占位符:
[TITLE placeholder],[BODY placeholder] - 图像:
Image或Image (external) - 视频:
YouTube video: <id>或Video: <id> - 桌子:
Table (3x4)(行x列) - 线条:线条类型(例如。,
STRAIGHT_LINE) - 组:
Group (N items)
使用案例:
- 为AI助手提供详细的幻灯片上下文
- 了解对象布局和定位
- 计划修改现有幻灯片
- 可访问性:以文本方式描述幻灯片内容
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDeither slide_index or slide_id must be provided-无幻灯片参考slide not found: slide index N out of range-幻灯片索引无效slide not found: slide_id 'xxx' not found-幻灯片ID无效presentation not found-演示文稿不存在access denied to presentation-没有访问权限
add_slide
在演示文稿的指定位置添加新幻灯片。
输入:
{
"presentation_id": "abc123xyz",
"position": 2,
"layout": "TITLE_AND_BODY"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
position |
integer | 否 | 1基位置(0或省略=结束) |
layout |
string | 是 | 布局类型(请参阅下面支持的布局) |
支持的布局类型:
| 布局 | 描述 |
|---|---|
BLANK |
没有占位符的空幻灯片 |
CAPTION_ONLY |
底部的标题文本 |
TITLE |
标题幻灯片 |
TITLE_AND_BODY |
带有正文区域的标题 |
TITLE_AND_TWO_COLUMNS |
标题采用两列布局 |
TITLE_ONLY |
仅标题占位符 |
ONE_COLUMN_TEXT |
单列文本布局 |
MAIN_POINT |
重点布局 |
BIG_NUMBER |
大数字显示布局 |
SECTION_HEADER |
节标题幻灯片 |
SECTION_TITLE_AND_DESCRIPTION |
带说明的部分 |
输出:
{
"slide_index": 2,
"slide_id": "g123456789"
}
| 字段 | 类型 | 描述 |
|---|---|---|
slide_index |
integer | 1为基础的新幻灯片索引 |
slide_id |
string | 创建幻灯片的对象ID |
特征:
- 在演示文稿末尾放置0或省略的插入内容
- 超出滑块计数插入件末端的位置
- 自动在演示文稿中查找匹配的布局
- 如果没有完全匹配,则回退到第一个可用布局
- 如果演示文稿没有布局,则回退到预定义的布局类型
使用案例:
- 向现有演示文稿添加幻灯片
- 以编程方式构建演示文稿
- 在工作流中的特定位置插入幻灯片
示例:
在末尾添加幻灯片:
{
"presentation_id": "abc123",
"layout": "BLANK"
}
插入一张幻灯片作为第二张幻灯片:
{
"presentation_id": "abc123",
"position": 2,
"layout": "TITLE_AND_BODY"
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid layout type: layout is required-缺少布局invalid layout type: unsupported layout 'XXX'-未知布局类型presentation not found-演示文稿不存在access denied to presentation-无权修改
delete_slide
按索引或ID从演示文稿中删除幻灯片。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 2
}
或者通过幻灯片ID:
{
"presentation_id": "abc123xyz",
"slide_id": "g123456789"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 否* | 1要删除的幻灯片索引 |
slide_id |
string | 否* | 要删除的幻灯片的对象ID |
*要么 slide_index 或 slide_id 是必需的。如果两者都提供, slide_id 优先。
输出:
{
"deleted_slide_id": "g123456789",
"remaining_slide_count": 2
}
| 字段 | 类型 | 描述 |
|---|---|---|
deleted_slide_id |
string | 已删除幻灯片的对象ID |
remaining_slide_count |
integer | 删除后剩余的幻灯片数量 |
特征:
- 按从1开始的索引或按幻灯片对象ID删除
- 防止删除最后一张剩余幻灯片
- 返回带有更新幻灯片计数的确认
使用案例:
- 从演示文稿中删除不需要的幻灯片
- 填充后清理模板幻灯片
- 程序化演示文稿管理
示例:
删除第二张幻灯片:
{
"presentation_id": "abc123",
"slide_index": 2
}
按幻灯片ID删除:
{
"presentation_id": "abc123",
"slide_id": "g987654321"
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid slide reference: either slide_index or slide_id is required-未指定幻灯片cannot delete the last remaining slide: presentation must have at least one slide-最后滑动保护slide not found: slide with ID 'X' not found-幻灯片ID不存在slide not found: slide index X out of range (1-N)-索引超出界限presentation not found-演示文稿不存在access denied to presentation-无权修改
reorder_slides
将幻灯片移动到演示文稿中的新位置。
输入:
{
"presentation_id": "abc123xyz",
"slide_indices": [3, 5],
"insert_at": 1
}
或者通过幻灯片ID:
{
"presentation_id": "abc123xyz",
"slide_ids": ["g123456", "g789012"],
"insert_at": 2
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_indices |
array[int] | 没有* | 1个要移动的幻灯片索引 |
slide_ids |
array[string] | 否* | 要移动的幻灯片的对象ID |
insert_at |
integer | 是 | 1的幻灯片移动位置 |
*要么 slide_indices 或 slide_ids 是必需的。如果两者都提供, slide_ids 优先。
输出:
{
"new_order": [
{"index": 1, "slide_id": "g123456"},
{"index": 2, "slide_id": "g789012"},
{"index": 3, "slide_id": "g111111"},
{"index": 4, "slide_id": "g222222"}
]
}
| 字段 | 类型 | 描述 |
|---|---|---|
new_order |
array | 重新排序后完成幻灯片顺序 |
new_order[].index |
整数 | 1在新顺序中的位置 |
new_order[].slide_id |
string | 幻灯片的对象ID |
特征:
- 一次移动单个或多个幻灯片
- 一起移动的幻灯片保持其相对顺序
- 插入位置超出滑动计数夹至末端
- 返回完整的新幻灯片订单以供验证
使用案例:
- 重组演示流程
- 将部分移动到不同位置
- 审阅反馈后重新排序幻灯片
- 批量幻灯片组织
示例:
将第三张幻灯片移到开头:
{
"presentation_id": "abc123",
"slide_indices": [3],
"insert_at": 1
}
将幻灯片2和4移到末尾:
{
"presentation_id": "abc123",
"slide_indices": [2, 4],
"insert_at": 10
}
按ID移动特定幻灯片:
{
"presentation_id": "abc123",
"slide_ids": ["g987654", "g123456"],
"insert_at": 3
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDno slides specified to move: either slide_indices or slide_ids is required-未指定幻灯片invalid insert_at position: insert_at must be at least 1-位置无效slide not found: slide index X out of range (1-N)-索引超出界限slide not found: slide with ID 'X' not found-幻灯片ID不存在presentation not found-演示文稿不存在access denied to presentation-无权修改
duplicate_slide
复制演示文稿中的现有幻灯片,可以选择将副本放置在特定位置。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 2
}
或者通过幻灯片ID:
{
"presentation_id": "abc123xyz",
"slide_id": "g123456789",
"insert_at": 1
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 否* | 1要复制的幻灯片索引 |
slide_id |
string | 否* | 要复制的幻灯片对象ID |
insert_at |
integer | 否 | 1副本的位置(0或省略=源幻灯片之后) |
*要么 slide_index 或 slide_id 是必需的。如果两者都提供, slide_id 优先。
输出:
{
"slide_index": 3,
"slide_id": "g987654321"
}
| 字段 | 类型 | 描述 |
|---|---|---|
slide_index |
integer | 1为基础的新复制幻灯片索引 |
slide_id |
string | 新复制幻灯片的对象ID |
特征:
- 创建包含所有对象的源幻灯片的精确副本
- 默认位置(insert_at省略或0)将副本放在源幻灯片之后
- 超出滑动计数的插入位置被夹紧到底
- 如果移动操作失败,将滑块返回默认位置并发出警告
- 使用Google幻灯片API
DuplicateObjectRequest用于原子复制
使用案例:
- 创建现有幻灯片的变体
- 构建重复的幻灯片部分(议程、分隔符)
- 修改前将幻灯片保留为备份
- 基于模板的幻灯片生成
示例:
复制幻灯片2(副本放在幻灯片2后面的位置3):
{
"presentation_id": "abc123",
"slide_index": 2
}
按ID复制幻灯片并移动到开头:
{
"presentation_id": "abc123",
"slide_id": "g987654321",
"insert_at": 1
}
将最后一张幻灯片复制到末尾:
{
"presentation_id": "abc123",
"slide_index": 5,
"insert_at": 6
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid slide reference: either slide_index or slide_id is required-未指定幻灯片slide not found: slide with ID 'X' not found-幻灯片ID不存在slide not found: slide index X out of range (1-N)-索引超出界限presentation not found-演示文稿不存在access denied to presentation-无权修改failed to duplicate slide-复制操作失败
list_objects
列出幻灯片上的所有对象,并可选择按幻灯片索引和对象类型进行筛选。
输入:
{
"presentation_id": "abc123xyz"
}
使用过滤器:
{
"presentation_id": "abc123xyz",
"slide_indices": [1, 3],
"object_types": ["IMAGE", "VIDEO"]
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_indices |
integer[] | 否 | 1要包含的幻灯片索引(默认:所有幻灯片) |
object_types |
string[] | 否 | 要包含的对象类型(默认值:所有类型) |
支持的对象类型:
TEXT_BOX,RECTANGLE,ELLIPSE,TRIANGLE等等。(形状)IMAGE,VIDEO,TABLE,LINEGROUP,SHEETS_CHART,WORD_ART
输出:
{
"presentation_id": "abc123xyz",
"objects": [
{
"slide_index": 1,
"object_id": "g123456789",
"object_type": "TEXT_BOX",
"position": {"x": 100, "y": 50},
"size": {"width": 300, "height": 100},
"z_order": 0,
"content_preview": "Hello World"
},
{
"slide_index": 1,
"object_id": "g987654321",
"object_type": "IMAGE",
"position": {"x": 400, "y": 150},
"size": {"width": 200, "height": 200},
"z_order": 1,
"content_preview": ""
}
],
"total_count": 2,
"filtered_by": {
"slide_indices": [1],
"object_types": ["TEXT_BOX", "IMAGE"]
}
}
| 字段 | 类型 | 描述 |
|---|---|---|
presentation_id |
string | 演示文稿ID |
objects |
array | 对象列表数组 |
total_count |
integer | 返回的对象总数 |
filtered_by |
object | 应用了筛选器(仅当指定了筛选器时) |
对象列表字段:
| 字段 | 类型 | 描述 |
|---|---|---|
slide_index |
integer | 1包含对象的幻灯片索引 |
object_id |
string | 唯一对象标识符 |
object_type |
string | 对象的类型(TEXT_BOX、IMAGE等) |
position |
object | 对象在点{x,y}中的位置 |
size |
object | 以点为单位的对象尺寸{宽度、高度} |
z_order |
integer | 分层位置(较低=较后) |
content_preview |
string | 文本内容的前100个字符(用于文本对象) |
特征:
- 在未应用过滤器的情况下列出所有幻灯片中的对象
- 按幻灯片索引(从1开始)过滤以限制范围
- 按对象类型筛选以查找特定元素
- 位置和大小(标准幻灯片:720x405点)
- 带文本形状的内容预览(前100个字符)
- Z顺序表示滑块上的堆叠顺序
- 递归地将对象包含在组中
使用案例:
- 清点演示文稿中的所有对象
- 查找所有要替换的图像
- 查找视频以进行播放配置
- 识别用于批量文本操作的文本框
- 统计分析对象类型
示例:
列出演示文稿中的所有对象:
{
"presentation_id": "abc123"
}
仅列出图像和视频:
{
"presentation_id": "abc123",
"object_types": ["IMAGE", "VIDEO"]
}
列出特定幻灯片中的对象:
{
"presentation_id": "abc123",
"slide_indices": [1, 3, 5]
}
组合滤镜-仅来自第一张幻灯片的图像:
{
"presentation_id": "abc123",
"slide_indices": [1],
"object_types": ["IMAGE"]
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-没有访问权限slides API error-发生API错误
get_object
通过特定对象的ID获取其详细信息。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "g123456789"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 唯一对象标识符 |
输出:
{
"presentation_id": "abc123xyz",
"object_id": "g123456789",
"object_type": "TEXT_BOX",
"slide_index": 1,
"position": {"x": 100, "y": 50},
"size": {"width": 300, "height": 100},
"shape": {
"shape_type": "TEXT_BOX",
"text": "Hello World",
"text_style": {
"font_family": "Arial",
"font_size": 24,
"bold": true,
"color": "#FF0000",
"link_url": "https://example.com"
},
"fill": {
"type": "SOLID",
"solid_color": "#007FFF"
},
"outline": {
"color": "#000000",
"weight": 2,
"dash_style": "SOLID"
},
"placeholder_type": "TITLE"
}
}
特定类型的输出字段:
输出包括一个基于以下内容的特定类型字段 object_type:
| 对象类型 | 字段 | 描述 |
|---|---|---|
| TEXT_BOX、矩形等。 | shape |
形状属性,包括文本、样式、填充、轮廓 |
| 图像 | image |
图像属性,包括URL、裁剪、亮度、对比度 |
| 桌子 | table |
具有行、列和单元格内容的表结构 |
| 视频 | video |
视频属性,包括ID、源、定时、自动播放 |
| 线路 | line |
线条属性,包括类型、箭头、颜色、粗细 |
| 集团 | group |
包含儿童数量和儿童ID的组 |
| 图纸_图表 | chart |
带有电子表格ID和图表ID的图纸图表 |
| WORD_ART | word_art |
带有渲染文本的文字艺术 |
形状详细信息(shape 字段):
{
"shape_type": "TEXT_BOX",
"text": "Content text",
"text_style": {
"font_family": "Arial",
"font_size": 24,
"bold": true,
"italic": false,
"underline": false,
"color": "#FF0000",
"link_url": "https://..."
},
"fill": {
"type": "SOLID",
"solid_color": "#FFFFFF"
},
"outline": {
"color": "#000000",
"weight": 1,
"dash_style": "SOLID"
},
"placeholder_type": "TITLE"
}
图像详细信息(image 字段):
{
"content_url": "https://...",
"source_url": "https://...",
"brightness": 0.5,
"contrast": 0.3,
"transparency": 0.1,
"recolor": "GRAYSCALE",
"crop": {
"top": 0.1,
"bottom": 0.2,
"left": 0.05,
"right": 0.15
}
}
表详细信息(table 字段):
{
"rows": 3,
"columns": 4,
"cells": [
[
{"row": 0, "column": 0, "text": "Header 1", "row_span": 1, "column_span": 1, "background": "#E5E5E5"},
{"row": 0, "column": 1, "text": "Header 2"}
],
[
{"row": 1, "column": 0, "text": "Cell A1"},
{"row": 1, "column": 1, "text": "Cell B1"}
]
]
}
视频详情(video 字段):
{
"video_id": "dQw4w9WgXcQ",
"source": "YOUTUBE",
"url": "https://www.youtube.com/watch?v=...",
"start_time": 30,
"end_time": 60,
"autoplay": true,
"mute": false
}
线路详细信息(line 字段):
{
"line_type": "STRAIGHT_CONNECTOR_1",
"start_arrow": "ARROW",
"end_arrow": "NONE",
"color": "#0000FF",
"weight": 3,
"dash_style": "DASH"
}
组详细信息(group 字段):
{
"child_count": 3,
"child_ids": ["child-1", "child-2", "child-3"]
}
特征:
- 根据类型返回完整的对象属性
- 在演示文稿中的任何位置查找对象(包括嵌套在组中的对象)
- 位置和大小(标准幻灯片:720x405点)
- 返回的颜色为十六进制字符串(#RRGGBB)或主题引用(主题:ACCENT1)
- 视频时间(秒)(从内部毫秒转换而来)
- 文本样式包括字体、大小、粗体/斜体、颜色和超链接
使用案例:
- 修改前检查对象属性
- 获得精确的复制样式
- 提取文本内容和格式
- 检索图像URL和调整
- 检查视频定时和播放设置
- 通过子ID导航组内容
示例:
获取形状的详细信息:
{
"presentation_id": "abc123",
"object_id": "shape-xyz"
}
获取图像的属性:
{
"presentation_id": "abc123",
"object_id": "image-123"
}
错误:
object not found: object 'xyz' not found in presentation-找不到对象IDobject not found: object_id is required-空对象IDinvalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-没有访问权限slides API error-发生API错误
add_text_box
使用可选样式向幻灯片添加文本框。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 1,
"text": "Hello World",
"position": {"x": 100, "y": 50},
"size": {"width": 300, "height": 100},
"style": {
"font_family": "Arial",
"font_size": 24,
"bold": true,
"italic": false,
"color": "#FF0000"
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 否* | 1目标幻灯片的索引 |
slide_id |
string | 否* | 目标幻灯片的对象ID |
text |
string | 是 | 文本框的文本内容 |
position |
object | 否 | 点中的位置(默认值:0,0) |
position.x |
number | No | 从左边缘开始的点中的X坐标 |
position.y |
number | No | 从上边缘算起的Y坐标 |
size |
object | 是 | 以点为单位的大小 |
size.width |
number | Yes | 宽度(点数)(必须大于0) |
size.height |
number | Yes | 高度(必须大于0) |
style |
object | 否 | 文本样式选项 |
style.font_family |
string | 否 | 字体系列名称(例如“Arial”) |
style.font_size |
integer | 否 | 字体大小(以点为单位) |
style.bold |
boolean | 否 | 粗体文本 |
style.italic |
boolean | 否 | 斜体文本 |
style.color |
string | 否 | 十六进制颜色字符串(例如“#FF0000”) |
*要么 slide_index 或 slide_id 必须提供。
输出:
{
"object_id": "textbox_1234567890123456"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 创建的文本框的唯一标识符 |
特征:
- 使用基于1的幻灯片索引或幻灯片ID以获得灵活性
- 如果未指定,则位置默认为(0,0)
- 尺寸要求为正宽度和正高度
- 样式设置是可选的-仅应用指定的样式字段
- 标准幻灯片尺寸:720x405点
- 1点=12700 EMU(英制公制单位)
使用案例:
- 为幻灯片添加标题和标题
- 插入正文内容
- 创建注释或标签
- 添加样式化标题
- 将文本放置在特定位置
示例:
添加一个简单的文本框:
{
"presentation_id": "abc123",
"slide_index": 1,
"text": "Hello World",
"size": {"width": 200, "height": 50}
}
添加样式化标题:
{
"presentation_id": "abc123",
"slide_id": "g123456",
"text": "Quarterly Report",
"position": {"x": 110, "y": 20},
"size": {"width": 500, "height": 60},
"style": {
"font_family": "Arial",
"font_size": 36,
"bold": true,
"color": "#0000FF"
}
}
错误:
text content is required-提供的文本为空size (width and height) is required-尺寸缺失或尺寸≤0invalid slide reference: either slide_index or slide_id must be provided-未提供幻灯片参考slide not found-幻灯片索引超出范围或未找到幻灯片IDinvalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-无权修改failed to add text box-创建过程中出现API错误
modify_text
修改现有形状中的文本内容(替换、追加、预置或删除)。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "g123456789",
"action": "replace",
"text": "New text content"
}
对于部分更换:
{
"presentation_id": "abc123xyz",
"object_id": "g123456789",
"action": "replace",
"text": "REPLACED",
"start_index": 5,
"end_index": 10
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 包含要修改的文本的形状的ID |
action |
string | 是 | 要执行的操作: replace, append, prepend,或 delete |
text |
string | 条件性 | 新文本内容(替换/追加/预置时需要,删除时不需要) |
start_index |
integer | 否 | 部分替换的起始索引(从0开始) |
end_index |
integer | 否 | 部分替换的结束索引(从0开始,不包括) |
行动:
| 动作 | 描述 |
|---|---|
replace |
替换形状中的所有文本,如果提供了索引,则替换部分文本 |
append |
在现有内容末尾添加文本 |
prepend |
在现有内容的开头添加文本 |
delete |
从形状中删除所有文本 |
输出:
{
"object_id": "g123456789",
"updated_text": "New text content",
"action": "replace"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改对象的ID |
updated_text |
string | 修改后的文本内容 |
action |
string | 执行的操作 |
特征:
- 支持四种操作:全部替换、追加、前置、删除
- 使用start_index/end_index进行手术编辑的部分替换
- 适用于任何包含文本的形状(text_BOX、RECTANGE等)
- 返回预期的结果文本以供确认
- 验证目标对象是否支持文本修改
使用案例:
- 用实际内容更新占位符文本
- 为现有文本添加时间戳或签名
- 在重新填充之前清除文本框
- 在现有文本中进行有针对性的编辑
示例:
替换形状中的所有文本:
{
"presentation_id": "abc123",
"object_id": "title-shape",
"action": "replace",
"text": "Q1 2024 Report"
}
将文本添加到现有内容:
{
"presentation_id": "abc123",
"object_id": "body-shape",
"action": "append",
"text": "\n\nLast updated: January 2024"
}
替换部分文本(字符5-10):
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"action": "replace",
"text": "NEW",
"start_index": 5,
"end_index": 10
}
删除所有文本:
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"action": "delete"
}
错误:
invalid action: action must be 'replace', 'append', 'prepend', or 'delete'-未知操作text is required for this action: text is required for 'replace' action-缺少文本invalid object_id: object_id is required-缺少对象IDinvalid text range: start_index cannot be negative-索引无效invalid text range: start_index cannot be greater than end_index-范围无效object does not contain editable text-对象类型不支持文本object does not contain editable text: tables must be modified cell by cell-表格修改object not found: object 'xyz' not found in presentation-对象ID无效invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-无权修改
style_text
将样式应用于形状中的文本(字体、大小、颜色、粗体、斜体等)。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "shape-789",
"start_index": 0,
"end_index": 10,
"style": {
"font_family": "Arial",
"font_size": 24,
"bold": true,
"italic": false,
"underline": true,
"strikethrough": false,
"foreground_color": "#FF0000",
"background_color": "#FFFF00",
"link_url": "https://example.com"
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 包含文本的形状的ID |
start_index |
integer | 否 | 起始字符索引(从0开始)。全文省略 |
end_index |
integer | 否 | 结束字符索引(不包括)。全文省略 |
style |
object | 是 | 设置要应用的样式属性 |
style.font_family |
string | 否 | 字体系列名称(例如,“Arial”、“Times New Roman”) |
style.font_size |
integer | 否 | 字体大小(以点为单位) |
style.bold |
boolean | 否 | 应用粗体格式 |
style.italic |
boolean | 否 | 应用斜体格式 |
style.underline |
boolean | 否 | 应用下划线格式 |
style.strikethrough |
boolean | 否 | 通过格式化应用删除线 |
style.foreground_color |
string | 否 | 文本颜色为十六进制(例如,“#FF0000”) |
style.background_color |
string | 否 | 文本突出显示颜色为十六进制(例如,“#FFFF00”) |
style.link_url |
string | 否 | 创建超链接的URL |
输出:
{
"object_id": "shape-789",
"applied_styles": [
"font_family=Arial",
"font_size=24pt",
"bold=true",
"italic=false",
"underline=true",
"strikethrough=false",
"foreground_color=#FF0000",
"background_color=#FFFF00",
"link_url=https://example.com"
],
"text_range": "FIXED_RANGE (0-10)"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 样式化对象的ID |
applied_styles |
array | 已应用的样式属性列表 |
text_range |
string | 范围描述:“ALL”或“FIXED_Range(开始-结束)” |
特征:
- 在一次调用中应用多个样式属性
- 设置整个文本内容或特定字符范围的样式
- 支持所有标准文本格式选项
- 布尔值区分“设置为false”和“未设置”
- 指定为十六进制字符串的颜色(#RRGGBB格式)
- 使用link_url创建可点击的超链接
使用案例:
- 用粗体和大字体格式化标题
- 用颜色突出显示重要文本
- 向文本添加超链接
- 在文本元素之间应用一致的样式
- 通过将属性设置为false删除格式
示例:
将文本设置为粗体和红色:
{
"presentation_id": "abc123xyz",
"object_id": "shape-789",
"style": {
"bold": true,
"foreground_color": "#FF0000"
}
}
风格特定字符(前5个字符):
{
"presentation_id": "abc123xyz",
"object_id": "shape-789",
"start_index": 0,
"end_index": 5,
"style": {
"font_size": 36,
"underline": true
}
}
向文本添加超链接:
{
"presentation_id": "abc123xyz",
"object_id": "shape-789",
"style": {
"link_url": "https://example.com",
"foreground_color": "#0000FF",
"underline": true
}
}
错误:
no style properties provided-样式对象为空或缺失invalid object_id: object_id is required-缺少对象IDinvalid text range: start_index cannot be negative-索引无效invalid text range: end_index cannot be negative-索引无效invalid text range: start_index cannot be greater than end_index-范围无效object does not contain text-对象类型不支持文本样式object does not contain editable text: tables must be styled cell by cell-桌子造型object not found: object 'xyz' not found in presentation-对象ID无效invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-无权修改
format_paragraph
设置段落格式选项,如对齐、间距和缩进。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"paragraph_index": 0,
"formatting": {
"alignment": "CENTER",
"line_spacing": 150,
"space_above": 12,
"space_below": 12,
"indent_first_line": 36,
"indent_start": 18,
"indent_end": 18
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 包含文本的形状的ID |
paragraph_index |
integer | 否 | 从0开始的段落格式索引(如果省略,则全部列出) |
formatting |
object | 是 | 要应用的格式选项 |
格式选项:
| 属性 | 类型 | 描述 |
|---|---|---|
alignment |
string | 文本对齐方式: START, CENTER, END, JUSTIFIED |
line_spacing |
number | 行距百分比(100=单行,150=1.5行,200=双行) |
space_above |
number | 段落上方空格(以点为单位) |
space_below |
number | 段落下方空格(以点为单位) |
indent_first_line |
number | 第一行缩进点数 |
indent_start |
number | 左缩进点(用于LTR文本) |
indent_end |
number | 右缩进点(用于LTR文本) |
输出:
{
"object_id": "textbox_123",
"applied_formatting": [
"alignment=CENTER",
"line_spacing=150.0%",
"space_above=12.0pt"
],
"paragraph_scope": "ALL"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 格式化对象的ID |
applied_formatting |
array | 已应用的格式化属性列表 |
paragraph_scope |
字符串 | "ALL" 或 "INDEX (N)" 指出哪些段落是格式化的 |
示例-居中对齐所有段落:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"formatting": {
"alignment": "CENTER"
}
}
示例-使用多个选项设置特定段落的格式:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"paragraph_index": 1,
"formatting": {
"alignment": "JUSTIFIED",
"line_spacing": 150,
"indent_first_line": 36
}
}
错误:
no formatting properties provided-格式化对象为空或缺失invalid alignment value: must be START, CENTER, END, or JUSTIFIED-对齐方式无效invalid paragraph_index: paragraph_index cannot be negative-负指数invalid paragraph_index: paragraph index N is out of range (object has M paragraphs)-索引太大object does not contain text-对象类型不支持文本格式object does not contain editable text: tables must be formatted cell by cell-表格格式object not found: object 'xyz' not found in presentation-对象ID无效invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-无权修改
create_bullet_list
将文本转换为项目符号列表或向形状中的现有文本添加项目符号。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"bullet_style": "DISC",
"bullet_color": "#FF0000",
"paragraph_indices": [0, 2]
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 包含文本的形状的ID |
bullet_style |
string | 是 | 项目符号样式名称或完整预设名称 |
bullet_color |
string | 否 | 项目符号的十六进制颜色(例如。, #FF0000) |
paragraph_indices |
array | 否 | 要应用项目符号的段落的基于0的索引(如果省略,则全部使用) |
子弹样式:
| 用户友好名称 | API预设 | 说明 |
|---|---|---|
DISC |
子弹_DISC_CIRCLE_SQUARE | 实心圆子弹 |
CIRCLE |
公告_DISC_CIRCLE_SQUARE | 与DISC相同 |
SQUARE |
公告_DISC_CIRCLE_SQUARE | 与DISC相同 |
DIAMOND |
子弹_钻石_圆形_方形 | 钻石子弹 |
ARROW |
公告_箭头_钻石_钻石 | 箭头子弹 |
STAR |
子弹_弹头_方形 | 星形子弹 |
CHECKBOX |
公告_CHECKBOX | 复选框项目符号 |
也接受完整的预设名称(例如。, BULLET_DISC_CIRCLE_SQUARE).
输出:
{
"object_id": "textbox_123",
"bullet_preset": "BULLET_DISC_CIRCLE_SQUARE",
"paragraph_scope": "ALL",
"bullet_color": "#FF0000"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改对象的ID |
bullet_preset |
string | 实际应用的API预设 |
paragraph_scope |
字符串 | "ALL" 或 "INDICES [0, 2]" 指出哪些段落收到了项目符号 |
bullet_color |
string | 应用的颜色(仅在指定颜色时显示) |
示例-将光盘项目符号应用于所有段落:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"bullet_style": "DISC"
}
示例-应用彩色星形项目符号:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"bullet_style": "STAR",
"bullet_color": "#FFD700"
}
示例-将复选框项目符号应用于特定段落:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"bullet_style": "CHECKBOX",
"paragraph_indices": [0, 2, 4]
}
错误:
invalid bullet_style: bullet_style is required-空子弹样式invalid bullet_style: 'XYZ' is not a valid bullet style-样式名称无效invalid paragraph_index: paragraph indices cannot be negative-负指数invalid paragraph_index: paragraph index N is out of range (object has M paragraphs)-索引太大object does not contain text-对象类型不支持项目符号object does not contain editable text: tables must have bullets applied cell by cell-表对象object not found: object 'xyz' not found in presentation-对象ID无效invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-无权修改
create_numbered_list
将文本转换为编号列表或为形状中的现有文本添加编号。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"number_style": "DECIMAL",
"start_number": 1,
"paragraph_indices": [0, 2]
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 包含文本的形状的ID |
number_style |
string | 是 | 数字样式名称或完整预设名称 |
start_number |
integer | 否 | 起始编号(默认值:1) |
paragraph_indices |
array | 否 | 要应用编号的段落的基于0的索引(如果省略,则全部使用) |
数字样式:
| 用户友好名称 | API预设 | 说明 |
|---|---|---|
DECIMAL |
NUMBERED_DECIMAL_ALPHA_ROMAN | 1、2、3 |
ALPHA_UPPER |
编号_字母_字母_罗马 | A、B、C |
ALPHA_LOWER |
数字_ALPHA_ALPHA_ROMAN | a、b、c |
ROMAN_UPPER |
NUMBERED_UPPERROMAN_upperrafa_DECIMAL | I,II,III |
ROMAN_LOWER |
编号_ROMAN_UPERALPHA_DECIMAL | i,ii,iii |
也接受完整的预设名称(例如。, NUMBERED_DECIMAL_NESTED, NUMBERED_DECIMAL_ALPHA_ROMAN_PARENS).
输出:
{
"object_id": "textbox_123",
"number_preset": "NUMBERED_DECIMAL_ALPHA_ROMAN",
"paragraph_scope": "ALL",
"start_number": 1
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改对象的ID |
number_preset |
string | 实际应用的API预设 |
paragraph_scope |
字符串 | "ALL" 或 "INDICES [0, 2]" 指出哪些段落被编号 |
start_number |
integer | 应用的起始编号 |
示例-对所有段落应用十进制编号:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"number_style": "DECIMAL"
}
示例-应用大写罗马数字:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"number_style": "ROMAN_UPPER"
}
示例-对特定段落应用小写字母编号:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"number_style": "ALPHA_LOWER",
"paragraph_indices": [0, 2, 4]
}
错误:
invalid number_style: number_style is required-空数字样式invalid number_style: 'XYZ' is not a valid number style-样式名称无效invalid start_number: start_number must be at least 1-起始编号小于1invalid paragraph_index: paragraph indices cannot be negative-负指数invalid paragraph_index: paragraph index N is out of range (object has M paragraphs)-索引太大object does not contain text-对象类型不支持编号object does not contain editable text: tables must have numbering applied cell by cell-表对象object not found: object 'xyz' not found in presentation-对象ID无效invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-无权修改
modify_list
修改现有列表属性、删除列表格式或更改缩进。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"action": "modify",
"paragraph_indices": [0, 2],
"properties": {
"bullet_style": "STAR",
"color": "#FF0000"
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 包含文本的形状的ID |
action |
string | 是 | 要执行的操作: modify, remove, increase_indent, decrease_indent |
paragraph_indices |
array | 否 | 要对其应用操作的段落的基于0的索引(如果省略,则全部列出) |
properties |
object | For modify |
要修改的属性(必需 modify 行动) |
行动:
| 动作 | 描述 |
|---|---|
modify |
更改项目符号样式、数字样式或颜色(需要 properties) |
remove |
删除列表格式,转换为纯文本 |
increase_indent |
缩进增加18点(嵌套更深) |
decrease_indent |
压痕减少18点(最小值0) |
属性(用于 modify 动作):
| 属性 | 类型 | 描述 |
|---|---|---|
bullet_style |
string | 新项目符号样式: DISC, CIRCLE, SQUARE, DIAMOND, ARROW, STAR, CHECKBOX |
number_style |
string | 新数字样式: DECIMAL, ALPHA_UPPER, ALPHA_LOWER, ROMAN_UPPER, ROMAN_LOWER |
color |
string | 项目符号/数字的十六进制颜色(例如。, #FF0000) |
必须至少提供一处房产 modify 行动。
输出:
{
"object_id": "textbox_123",
"action": "modify",
"paragraph_scope": "ALL",
"result": "Modified: bullet_style=BULLET_STAR_CIRCLE_SQUARE, color=#FF0000"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改对象的ID |
action |
string | 执行的操作 |
paragraph_scope |
字符串 | "ALL" 或 "INDICES [0, 2]" 指出受影响的段落 |
result |
string | 更改内容的描述 |
示例-删除列表格式:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"action": "remove"
}
示例-增加缩进:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"action": "increase_indent"
}
示例-将项目符号样式更改为星号:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"action": "modify",
"properties": {
"bullet_style": "STAR"
}
}
示例-更改特定段落的列表颜色:
{
"presentation_id": "abc123xyz",
"object_id": "textbox_123",
"action": "modify",
"paragraph_indices": [0, 2],
"properties": {
"color": "#FF0000"
}
}
错误:
invalid list action: action must be 'modify', 'remove', 'increase_indent', or 'decrease_indent'-无效操作no list properties provided: properties are required for 'modify' action-缺少可修改的属性no list properties provided: at least one property (bullet_style, number_style, or color) must be provided-空属性invalid bullet_style: 'XYZ' is not a valid bullet style-无效的项目符号样式invalid number_style: 'XYZ' is not a valid number style-数字样式无效invalid paragraph_index: paragraph indices cannot be negative-负指数invalid paragraph_index: paragraph index N is out of range (object has M paragraphs)-索引太大object does not contain text-对象类型不支持文本object does not contain editable text: tables must have list properties modified cell by cell-表对象object not found: object 'xyz' not found in presentation-对象ID无效invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-无权修改
search_text
在演示文稿中的所有幻灯片中搜索文本。
输入:
{
"presentation_id": "abc123xyz",
"query": "important keyword",
"case_sensitive": false
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
query |
string | 是 | 要搜索的文本 |
case_sensitive |
boolean | 否 | 启用区分大小写的搜索(默认值:false) |
输出:
{
"presentation_id": "abc123xyz",
"query": "important keyword",
"case_sensitive": false,
"total_matches": 5,
"results": [
{
"slide_index": 1,
"slide_id": "g123456",
"matches": [
{
"object_id": "shape-789",
"object_type": "TEXT_BOX",
"start_index": 25,
"text_context": "...text before the important keyword and text after..."
}
]
},
{
"slide_index": 3,
"slide_id": "g789012",
"matches": [
{
"object_id": "table-1[0,2]",
"object_type": "TABLE_CELL",
"start_index": 5,
"text_context": "This important keyword appears in a table cell"
}
]
}
]
}
| 字段 | 类型 | 描述 |
|---|---|---|
presentation_id |
string | 搜索到的演示文稿ID |
query |
string | 使用的搜索查询 |
case_sensitive |
boolean | 搜索是否区分大小写 |
total_matches |
integer | 找到的匹配项总数 |
results |
array | 按幻灯片分组的结果 |
results[].slide_index |
整数 | 1基幻灯片索引 |
results[].slide_id |
string | 幻灯片的对象ID |
results[].matches |
array | 此幻灯片上找到的匹配项 |
matches[].object_id |
string | 包含匹配项的对象的ID(对于表:包括单元格位置) |
matches[].object_type |
string | 对象类型(TEXT_BOX、TABLE_CELL、SPEAKER_NOTES:TEXT_BOX等) |
matches[].start_index |
integer | 匹配开始的字符位置 |
matches[].text_context |
string | 环绕文本(匹配前后50个字符) |
特征:
- 搜索所有幻灯片、文本形状、表格和演讲者笔记
- 默认情况下不区分大小写(可配置为
case_sensitive) - 包括每场比赛的周围背景(50个字符)
- 结果按幻灯片分组,便于导航
- 递归搜索分组元素
- 表单元格匹配包括object_id中的行/列位置
- 扬声器笔记匹配在object_type中以“Speaker_notes:”作为前缀
使用案例:
- 在演示文稿中查找特定内容
- 查找替换前出现的所有术语
- 查看关键字在幻灯片中的显示位置
- 在演讲者笔记中查找内容
示例:
不区分大小写的搜索(默认):
{
"presentation_id": "abc123",
"query": "revenue"
}
区分大小写的搜索:
{
"presentation_id": "abc123",
"query": "Revenue",
"case_sensitive": true
}
错误:
invalid query: query is required-空搜索查询invalid presentation ID: presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied to presentation-没有访问权限
replace_text
在演示文稿中查找和替换文本。
输入:
{
"presentation_id": "abc123xyz",
"find": "{{name}}",
"replace_with": "John Doe",
"case_sensitive": false,
"scope": "all"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
find |
string | 是 | 要搜索的文本 |
replace_with |
string | 是 | 替换文本(空字符串删除匹配项) |
case_sensitive |
boolean | 否 | 启用区分大小写的匹配(默认值:false) |
scope |
string | 否 | 替换范围:“所有”、“幻灯片”、“对象”(默认值:“全部”) |
slide_id |
string | 条件性 | 范围为“slide”时为必填项 |
object_id |
string | 条件性 | 作用域为“object”时为必填项 |
输出:
{
"presentation_id": "abc123xyz",
"find": "{{name}}",
"replace_with": "John Doe",
"case_sensitive": false,
"scope": "all",
"replacement_count": 5,
"affected_objects": [
{
"slide_index": 1,
"slide_id": "g123456",
"object_id": "shape-789",
"object_type": "TEXT_BOX"
},
{
"slide_index": 2,
"slide_id": "g456789",
"object_id": "table-1",
"object_type": "TABLE"
}
]
}
| 字段 | 类型 | 描述 |
|---|---|---|
presentation_id |
string | 修改后的演示文稿ID |
find |
string | 使用的搜索词 |
replace_with |
string | 替换文本 |
case_sensitive |
boolean | 匹配是否区分大小写 |
scope |
string | 用于替换的范围 |
replacement_count |
integer | 替换的总数 |
affected_objects |
array | 包含匹配项的对象 |
affected_objects[].slide_index |
整数 | 1基幻灯片索引 |
affected_objects[].slide_id |
string | 包含幻灯片的对象ID |
affected_objects[].object_id |
string | 修改元素的对象ID |
affected_objects[].object_type |
string | 修改对象的类型(TEXT_BOX、TABLE等) |
特征:
- 使用谷歌幻灯片
ReplaceAllTextRequestAPI用于高效批量更换 - 范围
all替换整个演示文稿(默认) - 范围
slide特定幻灯片的限制 - 范围
object包含特定对象的幻灯片的限制 - 默认情况下不区分大小写(可配置)
- 空
replace_with有效删除所有匹配项 - 报告所有受影响的对象以供验证
使用案例:
- 模板邮件合并(替换像{{name}}这样的占位符)
- 演示文稿中的批量文本更新
- 删除草稿水印或占位符文本
- 纠正拼写错误或过时的信息
- 更新公司名称或产品名称
示例:
替换模板占位符:
{
"presentation_id": "abc123",
"find": "{{company_name}}",
"replace_with": "Acme Corporation"
}
特定幻灯片上的区分大小写的替换:
{
"presentation_id": "abc123",
"find": "Q3",
"replace_with": "Q4",
"case_sensitive": true,
"scope": "slide",
"slide_id": "g456789"
}
删除文本(替换为空):
{
"presentation_id": "abc123",
"find": "[DRAFT]",
"replace_with": ""
}
错误:
find text is required: find text cannot be empty-空查找文本invalid scope: scope must be 'all', 'slide', or 'object'-作用域值无效invalid scope: slide_id is required when scope is 'slide'-幻灯片作用域缺少slide_idinvalid scope: object_id is required when scope is 'object'-对象作用域缺少object_idslide not found-指定的slide_id不存在object not found-指定的object_id不存在presentation not found-演示文稿不存在access denied to presentation-无权修改
需要记录的更多工具:
内容操纵
add_text-向现有占位符添加文本style_text-应用文本格式format_paragraph-设置段落样式create_bullet_list-将文本转换为项目符号列表create_numbered_list-将文本转换为编号列表modify_list-修改列表属性、删除格式或更改缩进
媒体和对象
add_image
从base64编码数据向幻灯片添加图像。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 1,
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"position": {"x": 100, "y": 50},
"size": {"width": 300, "height": 200}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 否* | 1目标幻灯片的索引 |
slide_id |
string | 否* | 目标幻灯片的对象ID |
image_base64 |
string | 是 | Base64编码图像数据 |
position |
object | 否 | 点中的位置(默认值:0,0) |
position.x |
number | No | 从左边缘开始的点中的X坐标 |
position.y |
number | No | 从上边缘算起的Y坐标 |
size |
object | 否 | 以点为单位的大小(可选,保留纵横比) |
size.width |
number | No | 宽度(可选) |
size.height |
number | No | 高度(可选) |
*要么 slide_index 或 slide_id 必须提供。
输出:
{
"object_id": "image_1234567890123456"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 创建图像的唯一标识符 |
支持的图像格式:
- PNG(图像/PNG)
- JPEG(图像/JPEG)
- GIF(图片/GIF)
- WebP(图像/WebP)
- BMP(图像/BMP)
特征:
- 使用基于1的幻灯片索引或幻灯片ID以获得灵活性
- 自动从魔术字节中检测图像MIME类型
- 首先将图像上传到Google云端硬盘进行持久保存
- 使上传的文件可公开访问,以便幻灯片可以显示它
- 如果未指定,则位置默认为(0,0)
- 大小是可选的-如果省略,则使用原始图像尺寸
- 如果只指定宽度或高度,则保留纵横比
- 标准幻灯片尺寸:720x405点
- 1点=12700 EMU(英制公制单位)
使用案例:
- 在演示文稿中添加徽标
- 插入图表或图解
- 添加屏幕截图或照片
- 在幻灯片上创建图像库
- 使用图像生成程序化演示文稿
示例:
添加默认大小的图像:
{
"presentation_id": "abc123",
"slide_index": 1,
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA..."
}
在特定位置添加图像:
{
"presentation_id": "abc123",
"slide_id": "g123456",
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"position": {"x": 100, "y": 150}
}
添加具有特定大小的图像:
{
"presentation_id": "abc123",
"slide_index": 2,
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"position": {"x": 50, "y": 100},
"size": {"width": 400, "height": 300}
}
添加仅具有宽度的图像(保留纵横比):
{
"presentation_id": "abc123",
"slide_index": 1,
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"size": {"width": 200}
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid slide reference: either slide_index or slide_id is required-未提供幻灯片参考invalid image data: image_base64 is required-缺少图像数据invalid image data: base64 decoding failed-base64编码无效invalid image data: unable to detect image format-无法识别的图像格式invalid image size: size must have positive width and/or height-尺寸≤0invalid image position: position coordinates must be non-negative-负位置值failed to upload image to Drive-驱动器API上载错误slide not found-幻灯片索引超出范围或未找到幻灯片IDpresentation not found-演示文稿不存在access denied to presentation-无权修改failed to add image-创建图像时出现API错误
modify_image
修改演示文稿中现有图像的属性。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "image_1234567890",
"properties": {
"position": {"x": 100, "y": 50},
"size": {"width": 300, "height": 200},
"crop": {"top": 0.1, "bottom": 0.1, "left": 0.05, "right": 0.05},
"brightness": 0.3,
"contrast": -0.2,
"transparency": 0.5,
"recolor": "GRAYSCALE"
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 要修改的图像的对象ID |
properties |
object | 是 | 要修改的属性(至少需要一个) |
properties.position |
object | 否 | 点中的新位置 |
properties.position.x |
number | No | 从左边缘开始的点中的X坐标 |
properties.position.y |
number | No | 从上边缘算起的Y坐标 |
properties.size |
对象 | 否 | 新大小(以点为单位) |
properties.size.width |
number | No | 宽度(以点为单位) |
properties.size.height |
number | No | 高度(点数) |
properties.crop |
object | 否 | 作物百分比(0-1) |
properties.crop.top |
number | No | 从顶部裁剪的百分比(0-1) |
properties.crop.bottom |
number | No | 从底部裁剪的百分比(0-1) |
properties.crop.left |
number | 否 | 从左裁剪的百分比(0-1) |
properties.crop.right |
number | 否 | 从右侧裁剪的百分比(0-1) |
properties.brightness |
number | No | 亮度调节(-1到1) |
properties.contrast |
number | No | 对比度调整(-1到1) |
properties.transparency |
number | No | 透明度级别(0到1,其中0表示不透明) |
properties.recolor |
string | 否 | 重新着色预设名称或删除“无” |
输出:
{
"object_id": "image_1234567890",
"modified_properties": ["position", "brightness", "contrast"]
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改后的图像的对象ID |
modified_properties |
array | 已修改的属性列表 |
重新着色预设:
| 预设 | 描述 |
|---|---|
GRAYSCALE |
灰度重着色 |
SEPIA |
深褐色调 |
NEGATIVE |
负片颜色 |
LIGHT1 - LIGHT10 |
灯光主题变化 |
DARK1 - DARK10 |
黑暗主题变化 |
NONE |
删除重新着色效果 |
特征:
- 在一次调用中修改多个属性
- 位置和大小使用带绝对模式的UpdatePageElementTransformRequest
- 图像属性使用带字段掩码的UpdateImagePropertiesRequest
- 所有属性都是可选的,但必须至少指定一个
- 在进行API调用之前验证所有属性范围
- 重新着色“无”或“无”会消除任何现有的重新着色效果
- 位置和大小更改会保留其他变换属性
- 标准幻灯片尺寸:720x405点
- 1点=12700 EMU(英制公制单位)
使用案例:
- 初始放置后重新定位图像
- 调整图像大小以适应布局
- 裁剪图像以聚焦特定区域
- 调整图像亮度和对比度
- 使图像半透明以用于水印或覆盖
- 使用重新着色预设应用视觉效果
- 删除以前应用的重新着色效果
示例:
移动图像并调整其大小:
{
"presentation_id": "abc123",
"object_id": "image_xyz",
"properties": {
"position": {"x": 150, "y": 100},
"size": {"width": 400, "height": 300}
}
}
裁剪和调整亮度/对比度:
{
"presentation_id": "abc123",
"object_id": "image_xyz",
"properties": {
"crop": {"top": 0.1, "left": 0.1, "right": 0.1, "bottom": 0.1},
"brightness": 0.3,
"contrast": -0.2
}
}
应用灰度重着色:
{
"presentation_id": "abc123",
"object_id": "image_xyz",
"properties": {
"recolor": "GRAYSCALE"
}
}
删除重新着色效果:
{
"presentation_id": "abc123",
"object_id": "image_xyz",
"properties": {
"recolor": "none"
}
}
设置水印效果的透明度:
{
"presentation_id": "abc123",
"object_id": "image_xyz",
"properties": {
"transparency": 0.7
}
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDobject not found: object 'xyz' not found in presentation-对象不存在object is not an image: object 'xyz' is not an image (type: TEXT_BOX)-对象不是图像no image properties to modify-Properties对象为空或为nilcrop values must be between 0 and 1: top crop value X is invalid-作物值无效brightness must be between -1 and 1-亮度值无效contrast must be between -1 and 1-对比度值无效transparency must be between 0 and 1-透明度值无效invalid image size: size must have positive width and/or height-尺寸≤0invalid image position: position coordinates must be non-negative-负位置值presentation not found-演示文稿不存在access denied to presentation-无权修改failed to modify image-API修改时出错
modify_video
修改演示文稿中现有视频的属性。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "video_1234567890",
"properties": {
"position": {"x": 100, "y": 50},
"size": {"width": 400, "height": 225},
"start_time": 30.0,
"end_time": 120.0,
"autoplay": true,
"mute": false
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 要修改的视频的对象ID |
properties |
object | 是 | 要修改的属性(至少需要一个) |
properties.position |
object | 否 | 点中的新位置 |
properties.position.x |
number | No | 从左边缘开始的点中的X坐标 |
properties.position.y |
number | No | 从上边缘算起的Y坐标 |
properties.size |
对象 | 否 | 新大小(以点为单位) |
properties.size.width |
number | No | 宽度(以点为单位) |
properties.size.height |
number | No | 高度(点数) |
properties.start_time |
number | No | 视频开始时间(秒) |
properties.end_time |
number | No | 视频结束时间(秒) |
properties.autoplay |
boolean | 否 | 是否自动播放视频 |
properties.mute |
boolean | 否 | 是否静音视频 |
输出:
{
"object_id": "video_1234567890",
"modified_properties": ["position", "start_time", "autoplay"]
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改后的视频的对象ID |
modified_properties |
array | 已修改的属性列表 |
特征:
- 在一次调用中修改多个属性
- 位置和大小使用带绝对模式的UpdatePageElementTransformRequest
- 视频播放属性使用带字段掩码的UpdateVideoPropertiesRequest
- 所有属性都是可选的,但必须至少指定一个
- 在进行API调用之前验证所有属性范围
- 时间值以秒为单位(API转换为毫秒)
- 位置和大小更改会保留其他变换属性
- 标准幻灯片尺寸:720x405点
- 1点=12700 EMU(英制公制单位)
使用案例:
- 在初始放置后重新定位视频
- 调整视频大小以适应布局
- 调整视频播放范围(设置开始/结束时间)
- 启用演示模式的自动播放
- 将视频静音播放
示例:
移动和调整视频大小:
{
"presentation_id": "abc123",
"object_id": "video_xyz",
"properties": {
"position": {"x": 150, "y": 100},
"size": {"width": 500, "height": 280}
}
}
调整视频播放范围:
{
"presentation_id": "abc123",
"object_id": "video_xyz",
"properties": {
"start_time": 30.0,
"end_time": 120.0
}
}
启用自动播放和静音:
{
"presentation_id": "abc123",
"object_id": "video_xyz",
"properties": {
"autoplay": true,
"mute": true
}
}
一次修改所有属性:
{
"presentation_id": "abc123",
"object_id": "video_xyz",
"properties": {
"position": {"x": 50, "y": 50},
"size": {"width": 640, "height": 360},
"start_time": 10.0,
"end_time": 60.0,
"autoplay": true,
"mute": false
}
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDobject not found: object 'xyz' not found in presentation-对象不存在object is not a video: object 'xyz' is not a video (type: TEXT_BOX)-对象不是视频no video properties to modify-Properties对象为空或为nilinvalid video size: size must have positive width and/or height-尺寸≤0或为负invalid video position: position coordinates must be non-negative-负位置值invalid video time: start_time cannot be negative-负开始时间invalid video time: end_time cannot be negative-负结束时间invalid video time range: end_time must be greater than start_time-结束时间不在开始之后presentation not found-演示文稿不存在access denied to presentation-无权修改failed to modify video-API修改时出错
replace_image
用新图像替换现有图像,同时可选择保留大小和位置。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "image_1234567890",
"image_base64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"preserve_size": true
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 要替换的图像的对象ID |
image_base64 |
string | 是 | Base64编码图像数据 |
preserve_size |
boolean | 否 | 是否保留原始大小(默认值:true) |
输出:
{
"object_id": "image_1234567890",
"new_object_id": "image_9876543210",
"preserved_size": true
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 原始图像的对象ID |
new_object_id |
string | 新图像的对象ID(自替换创建新对象以来始终设置) |
preserved_size |
boolean | 是否保留了原始大小 |
支持的图像格式:
| 格式 | 魔术字节 |
|---|---|
| PNG | 89 50 4E 47 |
| JPEG | FF D8 FF |
| GIF | 47 49 46 (GIF) |
| WebP | 52 49 46 46...57 45 42 50 (RIFF…WEBP) |
| BMP | 42 4D (BM) |
特征:
- 通过删除旧图像并在同一位置创建新图像来替换图像内容
- 通过仿射变换(translateX、translateY、缩放、剪切)保持原始位置
- 当preserve_size为true时保留原始大小(默认)
- 首先将新图像上传到Google Drive,然后在幻灯片API中引用它
- 使上载的图像可公开访问,以供幻灯片API阅读
- 自动从魔术字节中检测图像MIME类型
- 返回新的对象ID,因为图像替换创建了一个新对象
使用案例:
- 用最终版本更新占位符图像
- 在演示文稿中替换徽标或品牌图像
- 替换过时的屏幕截图或图表
- 用新的数据可视化更新图表或图形
- 用生产就绪版本替换草稿图像
示例:
替换保留原始大小的图像:
{
"presentation_id": "abc123",
"object_id": "image_xyz",
"image_base64": "iVBORw0KGgo...",
"preserve_size": true
}
使用新图像的自然大小替换图像:
{
"presentation_id": "abc123",
"object_id": "image_xyz",
"image_base64": "iVBORw0KGgo...",
"preserve_size": false
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDobject not found: object_id is required-空对象IDinvalid image data: image_base64 is required-空图像数据invalid image data: illegal base64 data-base64编码格式错误invalid image data: unable to detect image format-无法识别的图像格式object not found: object 'xyz' not found in presentation-对象不存在object is not an image: object 'xyz' is not an image (type: TEXT_BOX)-对象不是图像failed to upload image-驱动器API上载失败presentation not found-演示文稿不存在access denied to presentation-无权修改failed to replace image-更换过程中出现API错误
create_shape
使用可选的填充和轮廓样式在幻灯片上创建形状。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 1,
"shape_type": "RECTANGLE",
"position": {"x": 100, "y": 50},
"size": {"width": 200, "height": 100},
"fill_color": "#007FFF",
"outline_color": "#000000",
"outline_weight": 2
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 否* | 1目标幻灯片的索引 |
slide_id |
string | 否* | 目标幻灯片的对象ID |
shape_type |
string | Yes | 形状类型(矩形、椭圆等) |
position |
object | 否 | 点中的位置(默认值:0,0) |
position.x |
number | No | 从左边缘开始的点中的X坐标 |
position.y |
number | No | 从上边缘算起的Y坐标 |
size |
object | 是 | 以点为单位的大小 |
size.width |
number | Yes | 宽度(必须为正) |
size.height |
number | Yes | 高度(必须为正) |
fill_color |
string | 否 | 将颜色填充为十六进制字符串(#RRGGBB)或“透明” |
outline_color |
string | 否 | 轮廓颜色为十六进制字符串(#RRGGBB)或“透明” |
outline_weight |
number | No | 轮廓权重(必须为正) |
*要么 slide_index 或 slide_id 必须提供。
输出:
{
"object_id": "shape_1234567890123456"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 创建的形状的唯一标识符 |
支持的形状类型:
| 类别 | 形状类型 |
|---|---|
| 基础 | RECTANGLE, ROUND_RECTANGLE, ELLIPSE, TRIANGLE, DIAMOND, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, DECAGON, DODECAGON, PARALLELOGRAM, TRAPEZOID |
| 星星 | STAR_4, STAR_5, STAR_6, STAR_7, STAR_8, STAR_10, STAR_12, STAR_16, STAR_24, STAR_32 |
| 箭头 | ARROW_RIGHT, ARROW_LEFT, ARROW_UP, ARROW_DOWN, ARROW_LEFT_RIGHT, ARROW_UP_DOWN, NOTCHED_RIGHT_ARROW, BENT_ARROW, U_TURN_ARROW, CURVED_RIGHT_ARROW, CURVED_LEFT_ARROW, CURVED_UP_ARROW, CURVED_DOWN_ARROW, STRIPED_RIGHT_ARROW, CHEVRON, HOME_PLATE |
| 标注 | RECTANGULAR_CALLOUT, ROUNDED_RECTANGULAR_CALLOUT, ELLIPTICAL_CALLOUT, WEDGE_RECTANGLE_CALLOUT, WEDGE_ROUND_RECT_CALLOUT, WEDGE_ELLIPSE_CALLOUT, CLOUD_CALLOUT |
| 流程图 | FLOWCHART_PROCESS, FLOWCHART_DECISION, FLOWCHART_INPUT_OUTPUT, FLOWCHART_PREDEFINED_PROCESS, FLOWCHART_INTERNAL_STORAGE, FLOWCHART_DOCUMENT, FLOWCHART_MULTIDOCUMENT, FLOWCHART_TERMINATOR, FLOWCHART_PREPARATION, FLOWCHART_MANUAL_INPUT, FLOWCHART_MANUAL_OPERATION, FLOWCHART_CONNECTOR, FLOWCHART_PUNCHED_CARD, FLOWCHART_PUNCHED_TAPE, FLOWCHART_SUMMING_JUNCTION, FLOWCHART_OR, FLOWCHART_COLLATE, FLOWCHART_SORT, FLOWCHART_EXTRACT, FLOWCHART_MERGE, FLOWCHART_OFFLINE_STORAGE, FLOWCHART_ONLINE_STORAGE, FLOWCHART_MAGNETIC_TAPE, FLOWCHART_MAGNETIC_DISK, FLOWCHART_MAGNETIC_DRUM, FLOWCHART_DISPLAY, FLOWCHART_DELAY, FLOWCHART_ALTERNATE_PROCESS, FLOWCHART_DATA |
| 方程式 | PLUS, MINUS, MULTIPLY, DIVIDE, EQUAL, NOT_EQUAL |
| 阻止 | CUBE, CAN, BEVEL, FOLDED_CORNER, SMILEY_FACE, DONUT, NO_SMOKING, BLOCK_ARC, HEART, LIGHTNING_BOLT, SUN, MOON, CLOUD, ARC, PLAQUE, FRAME, HALF_FRAME, CORNER, DIAGONAL_STRIPE, CHORD, PIE, L_SHAPE, CORNER_RIBBON, RIBBON, RIBBON_2, WAVE, DOUBLE_WAVE, CROSS, IRREGULAR_SEAL_1, IRREGULAR_SEAL_2, TEARDROP |
| 直角 | SNIP_1_RECTANGLE, SNIP_2_SAME_RECTANGLE, SNIP_2_DIAGONAL_RECTANGLE, SNIP_ROUND_RECTANGLE, ROUND_1_RECTANGLE, ROUND_2_SAME_RECTANGLE, ROUND_2_DIAGONAL_RECTANGLE |
| 支架 | LEFT_BRACKET, RIGHT_BRACKET, LEFT_BRACE, RIGHT_BRACE, LEFT_RIGHT_BRACKET, BRACKET_PAIR, BRACE_PAIR |
特征:
- 使用基于1的幻灯片索引或幻灯片ID以获得灵活性
- 形状类型名称不区分大小写(标准化为大写)
- 如果未指定,则位置默认为(0,0)
- 填充颜色支持十六进制颜色或“透明”表示无填充
- 轮廓颜色支持十六进制颜色或“透明”表示没有轮廓
- 轮廓权重以点为单位指定边界厚度
- 标准幻灯片尺寸:720x405点
- 1点=12700 EMU(英制公制单位)
使用案例:
- 创建图表和流程图
- 为幻灯片添加装饰性形状
- 构建组织结构图
- 创建详图索引注释
- 绘制工艺流程
示例:
创建一个简单的矩形:
{
"presentation_id": "abc123",
"slide_index": 1,
"shape_type": "RECTANGLE",
"position": {"x": 100, "y": 100},
"size": {"width": 200, "height": 100}
}
使用填充颜色创建星形:
{
"presentation_id": "abc123",
"slide_id": "g123456",
"shape_type": "STAR_5",
"position": {"x": 300, "y": 150},
"size": {"width": 100, "height": 100},
"fill_color": "#FFD700"
}
创建带轮廓的箭头:
{
"presentation_id": "abc123",
"slide_index": 2,
"shape_type": "ARROW_RIGHT",
"position": {"x": 50, "y": 200},
"size": {"width": 150, "height": 50},
"fill_color": "#007FFF",
"outline_color": "#000000",
"outline_weight": 2
}
创建仅带边框的透明形状:
{
"presentation_id": "abc123",
"slide_index": 1,
"shape_type": "ELLIPSE",
"position": {"x": 200, "y": 100},
"size": {"width": 150, "height": 150},
"fill_color": "transparent",
"outline_color": "#FF0000",
"outline_weight": 3
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid slide reference: either slide_index or slide_id is required-未提供幻灯片参考invalid shape type: shape_type is required-缺少形状类型invalid shape type: 'X' is not a valid shape type-不支持的形状类型invalid size: size is required with positive width and height-大小缺失或无效outline weight must be positive-外形重量≤0slide not found-幻灯片索引超出范围或未找到幻灯片IDpresentation not found-演示文稿不存在access denied to presentation-无权修改failed to create shape-形状创建过程中出现API错误
create_table
在幻灯片上创建具有指定行和列的表格。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 1,
"rows": 3,
"columns": 4,
"position": {"x": 100, "y": 50},
"size": {"width": 400, "height": 200}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 否* | 1目标幻灯片的索引 |
slide_id |
string | 否* | 目标幻灯片的对象ID |
rows |
integer | 是 | 行数(最小1) |
columns |
integer | 是 | 列数(最小1) |
position |
object | 否 | 点中的位置(默认值:0,0) |
position.x |
number | No | 从左边缘开始的点中的X坐标 |
position.y |
number | No | 从上边缘算起的Y坐标 |
size |
对象 | 否 | 大小(可选) |
size.width |
number | No | 宽度(以点为单位)(必须为正) |
size.height |
number | No | 高度(必须为正) |
*要么 slide_index 或 slide_id 必须提供。
输出:
{
"object_id": "table_1234567890123456",
"rows": 3,
"columns": 4
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 创建的表的唯一标识符 |
rows |
integer | 表中的行数 |
columns |
integer | 表中的列数 |
特征:
- 创建具有指定维度的空表
- 使用基于1的幻灯片索引或幻灯片ID以获得灵活性
- 如果未指定,则位置默认为(0,0)
- 大小是可选的-如果没有提供,表将使用基于行/列的默认大小
- 标准幻灯片尺寸:720x405点
- 1点=12700 EMU(英制公制单位)
使用案例:
- 在演示文稿中创建数据表
- 构建比较矩阵
- 添加结构化内容布局
- 创建时间表或时间线
- 构建组织结构图
示例:
创建一个简单的3x4表格:
{
"presentation_id": "abc123",
"slide_index": 1,
"rows": 3,
"columns": 4
}
创建一个具有位置和大小的表:
{
"presentation_id": "abc123",
"slide_id": "g123456",
"rows": 5,
"columns": 3,
"position": {"x": 50, "y": 100},
"size": {"width": 600, "height": 300}
}
创建单单元格表:
{
"presentation_id": "abc123",
"slide_index": 1,
"rows": 1,
"columns": 1
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid slide reference: either slide_index or slide_id is required-未提供幻灯片参考rows must be at least 1-行数无效columns must be at least 1-列计数无效invalid size: size is required with positive width and height-无效大小(如果提供)slide not found-幻灯片索引超出范围或未找到幻灯片IDpresentation not found-演示文稿不存在access denied to presentation-无权修改failed to create table-创建表时出现API错误
modify_table_structure
在现有表中添加或删除行/列。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "table_xyz123",
"action": "add_row",
"index": 1,
"count": 1,
"insert_after": true
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 要修改的表的对象ID |
action |
string | 是 | 要执行的操作: add_row, delete_row, add_column, delete_column |
index |
integer | 是 | 从0开始添加/删除索引 |
count |
integer | 否 | 要添加/删除的行数/列数(默认值:1) |
insert_after |
boolean | 否 | 对于添加操作:在索引后插入(默认值:true) |
输出:
{
"object_id": "table_xyz123",
"action": "add_row",
"index": 1,
"count": 1,
"new_rows": 4,
"new_columns": 3
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改后的表的对象ID |
action |
string | 执行的操作(标准化小写) |
index |
integer | 用于操作的索引 |
count |
integer | 添加/删除的行数/列数 |
new_rows |
integer | 修改后更新的行数 |
new_columns |
integer | 修改后更新的列数 |
行动:
| 动作 | 描述 |
|---|---|
add_row |
在指定索引处添加行 |
delete_row |
删除从指定索引开始的行 |
add_column |
在指定索引处添加列 |
delete_column |
删除从指定索引开始的列 |
特征:
- 动作名称不区分大小写(add_row、add_row都有效)
- 索引从0开始(第一行/第一列为索引0)
- 对于添加动作,
insert_after控制位置:true(默认):在索引后插入(下面为行,右边为列)false:在索引前插入(上方为行,左侧为列)
- 对于删除操作,从索引开始删除并继续对计数项进行删除
- 验证删除后表是否至少有1行和1列
使用案例:
- 用新数据行扩展表
- 向现有表添加标题行
- 删除空行/空列
- 调整表格布局
- 根据内容动态调整表格大小
示例:
在行索引1后添加一行:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"action": "add_row",
"index": 1
}
在列索引0的右侧添加3列:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"action": "add_column",
"index": 0,
"count": 3
}
在索引0上方添加行(在开头):
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"action": "add_row",
"index": 0,
"insert_after": false
}
删除从索引1开始的2行:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"action": "delete_row",
"index": 1,
"count": 2
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid object ID: object_id is required-空对象IDinvalid table action: action must be 'add_row', 'delete_row', 'add_column', or 'delete_column'-无效操作invalid table index: index must be non-negative-负指数count must be at least 1-计数无效invalid table index: row/column index X is out of range-索引超出界限cannot delete all rows/columns-将留下0行或0列的表object is not a table-对象ID未引用表object not found-找不到表对象IDpresentation not found-演示文稿不存在access denied to presentation-无权修改failed to modify table structure-API修改时出错
merge_cells
合并或取消合并表中的单元格。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "table_xyz123",
"action": "merge",
"start_row": 0,
"start_column": 0,
"end_row": 2,
"end_column": 2
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 表的对象ID |
action |
string | 是 | 要执行的操作: merge 或 unmerge |
start_row |
integer | 用于合并 | 基于0的起始行索引 |
start_column |
integer | 用于合并 | 基于0的起始列索引 |
end_row |
integer | 用于合并 | 基于0的结束行索引(不包括) |
end_column |
integer | 用于合并 | 基于0的结束列索引(不包括) |
row |
integer | 用于取消合并 | 合并单元格的基于0的行索引 |
column |
integer | 用于取消合并 | 合并单元格的基于0的列索引 |
输出:
{
"object_id": "table_xyz123",
"action": "merge",
"range": "rows 0-1, columns 0-1"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 表的对象ID |
action |
string | 执行的操作(标准化小写) |
range |
string | 受影响范围的人类可读描述 |
行动:
| 动作 | 描述 |
|---|---|
merge |
合并指定矩形范围内的单元格 |
unmerge |
在指定位置取消合并以前合并的单元格 |
特征:
- 动作名称不区分大小写(merge、merge都有效)
- 对于合并:使用基于0的索引,并带有独占结束(如Python切片)
- 对于取消合并:指定合并单元格内的任何单元格位置
- 验证范围是否在表边界内
- 验证合并范围是否至少跨越2个单元格
使用案例:
- 创建跨多列的表头
- 合并类别标签的单元格
- 使用合并区域创建复杂的表格布局
- 取消合并以前合并的单元格以进行重组
示例:
合并2x2范围的单元格:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"action": "merge",
"start_row": 0,
"start_column": 0,
"end_row": 2,
"end_column": 2
}
合并整行(第0行,所有4列):
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"action": "merge",
"start_row": 0,
"start_column": 0,
"end_row": 1,
"end_column": 4
}
合并整个列(列0,所有3行):
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"action": "merge",
"start_row": 0,
"start_column": 0,
"end_row": 3,
"end_column": 1
}
在位置(1,2)处取消合并合并单元格:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"action": "unmerge",
"row": 1,
"column": 2
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid object ID: object_id is required-空对象IDinvalid merge action: action must be 'merge' or 'unmerge'-无效操作invalid merge range: start indices must be non-negative-负启动指数invalid merge range: end_row must be greater than start_row-行范围无效invalid merge range: end_column must be greater than start_column-列范围无效invalid merge range: end_row X exceeds table row count Y-行超出界限invalid merge range: end_column X exceeds table column count Y-列超出界限invalid merge range: merge range must span at least 2 cells-单细胞范围invalid merge range: row and column indices must be non-negative-负非大型指数invalid merge range: row X is out of range-取消合并行超出界限invalid merge range: column X is out of range-取消合并列超出界限object is not a table-对象ID未引用表object not found-找不到表对象IDpresentation not found-演示文稿不存在access denied to presentation-无权修改failed to merge cells-合并过程中出现API错误failed to unmerge cells-取消合并时出现API错误
modify_table_cell
修改表格单元格的内容和样式。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "table_xyz123",
"row": 0,
"column": 1,
"text": "Hello World",
"style": {
"font_family": "Arial",
"font_size": 18,
"bold": true,
"foreground_color": "#FF0000"
},
"alignment": {
"horizontal": "CENTER",
"vertical": "MIDDLE"
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 表的对象ID |
row |
integer | 是 | 基于0的行索引 |
column |
integer | 是 | 基于0的列索引 |
text |
string | 否 | 单元格文本内容(替换现有内容) |
style |
object | 否 | 文本样式选项 |
style.font_family |
string | 否 | 字体系列名称(例如“Arial”) |
style.font_size |
integer | 否 | 字体大小(以点为单位) |
style.bold |
boolean | 否 | 粗体文本 |
style.italic |
boolean | 否 | 斜体文本 |
style.underline |
boolean | 否 | 为文本加下划线 |
style.strikethrough |
boolean | 否 | 删除文本 |
style.foreground_color |
string | 否 | 文本颜色(十六进制,例如“#FF0000”) |
style.background_color |
string | 否 | 突出显示颜色(十六进制) |
alignment |
object | 否 | 单元格对齐选项 |
alignment.horizontal |
string | 否 | 水平: START, CENTER, END, JUSTIFIED |
alignment.vertical |
string | 否 | 垂直: TOP, MIDDLE, BOTTOM |
注: 至少一个 text, style,或 alignment 必须提供。
输出:
{
"object_id": "table_xyz123",
"row": 0,
"column": 1,
"modified_properties": ["text", "font_family=Arial", "bold=true", "horizontal_alignment=CENTER"]
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 表的对象ID |
row |
integer | 行索引 |
column |
integer | 列索引 |
modified_properties |
array | 已修改的属性列表 |
特征:
- 设置单元格文本内容(替换现有文本)
- 应用文本样式(字体、大小、粗体、斜体、颜色等)
- 设置水平对齐(段落级别)
- 设置垂直对齐(单元格级别)
- 对齐值不区分大小写(中心、center都有效)
- 无效的颜色将被默认忽略(其他样式仍适用)
使用案例:
- 用数据填充表单元格
- 格式化标题单元格(粗体,居中)
- 对数据单元格应用一致的样式
- 用颜色创建视觉上不同的类别
- 调整单元格内容对齐以提高可读性
示例:
设置单元格文本内容:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"row": 0,
"column": 1,
"text": "Hello World"
}
应用文本样式:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"row": 1,
"column": 0,
"style": {
"font_family": "Arial",
"font_size": 18,
"bold": true,
"foreground_color": "#FF0000"
}
}
设置水平对齐:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"row": 0,
"column": 0,
"alignment": {
"horizontal": "CENTER"
}
}
设置垂直对齐:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"row": 2,
"column": 1,
"alignment": {
"vertical": "MIDDLE"
}
}
结合文本、样式和对齐方式:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"row": 1,
"column": 2,
"text": "Styled Text",
"style": {
"bold": true,
"font_size": 24
},
"alignment": {
"horizontal": "END",
"vertical": "BOTTOM"
}
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid object ID: object_id is required-空对象IDinvalid cell index: row must be non-negative-负行索引invalid cell index: column must be non-negative-负列索引no modification specified: text, style, or alignment must be provided-无修改invalid horizontal alignment: must be START, CENTER, END, or JUSTIFIED-水平对齐无效invalid vertical alignment: must be TOP, MIDDLE, or BOTTOM-垂直对齐无效invalid cell index: row X is out of range (table has Y rows)-行超出界限invalid cell index: column X is out of range (table has Y columns)-列超出界限object is not a table-对象ID未引用表object not found-找不到表对象IDpresentation not found-演示文稿不存在access denied to presentation-无权修改failed to modify table cell-API修改时出错
style_table_cells
将视觉样式(背景色、边框)应用于表格单元格。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "table_xyz123",
"cells": "all",
"style": {
"background_color": "#E6F2FF",
"border_top": {
"color": "#000000",
"width": 2.0,
"dash_style": "SOLID"
}
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 表的对象ID |
cells |
string/array | 是 | 单元格选择(见下文) |
style |
object | 是 | 要应用的样式选项 |
style.background_color |
string | 否 | 单元格背景颜色(十六进制,例如“#FF0000”) |
style.border_top |
对象 | 否 | 顶部边框样式 |
style.border_bottom |
对象 | 否 | 底部边框样式 |
style.border_left |
object | 否 | 左边框样式 |
style.border_right |
对象 | 否 | 右边框样式 |
border.color |
string | 否 | 边框颜色(十六进制) |
border.width |
number | No | 边框宽度(以点为单位) |
border.dash_style |
string | 否 | 边框破折号样式(见下文) |
单元格选择选项:
| 格式 | 描述 |
|---|---|
"all" |
选择表中的所有单元格 |
"row:N" |
选择第N行中的所有单元格(从0开始) |
"column:N" |
选择N列中的所有单元格(从0开始) |
[{"row": 0, "column": 1}, ...] |
按位置选择特定单元格 |
边框虚线样式:
SOLID-实线(默认)DOT-虚线DASH-虚线DASH_DOT-交替使用破折号和圆点LONG_DASH-长距离冲刺LONG_DASH_DOT-长破折号和圆点
注: 必须至少提供一个样式属性。
输出:
{
"object_id": "table_xyz123",
"cells_affected": 6,
"applied_styles": ["background_color=#E6F2FF", "border_top(color=#000000,width=2.0)"]
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 表的对象ID |
cells_affected |
integer | 已设置样式的单元格数量 |
applied_styles |
array | 应用的样式列表 |
特征:
- 灵活的单元格选择:所有单元格、整行、整列或特定位置
- 使用UpdateTableCellProperties请求应用背景颜色
- 使用UpdateTableBorderProperties请求应用边框
- 一次通话中可以应用多个边框
- 选择器字符串不区分大小写(“ALL”、“ALL”、“Row:0”都有效)
- 达世币样式名称不区分大小写
使用案例:
- 用背景颜色突出显示标题行
- 为单独的部分添加边框
- 为可读性设计交替行的样式
- 强调带有边框的特定单元格
- 创建视觉上不同的表格区域
示例:
将背景颜色应用于所有单元格:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"cells": "all",
"style": {
"background_color": "#E6F2FF"
}
}
使用背景和边框设置标题行样式:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"cells": "row:0",
"style": {
"background_color": "#4A86E8",
"border_bottom": {
"color": "#000000",
"width": 2.0
}
}
}
将虚线边框应用于特定单元格:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"cells": [{"row": 1, "column": 0}, {"row": 1, "column": 1}],
"style": {
"border_top": {
"color": "#FF0000",
"width": 1.5,
"dash_style": "DASH"
}
}
}
设置整个列的样式:
{
"presentation_id": "abc123",
"object_id": "table_xyz",
"cells": "column:2",
"style": {
"background_color": "#F0F0F0"
}
}
错误:
invalid presentation ID: presentation_id is required-空演示文稿IDinvalid object ID: object_id is required-空对象IDno style specified: style is required-缺少样式对象no style specified: at least one style property must be specified-空样式对象invalid cell selector-单元格选择格式无效invalid cell selector: row X is out of range-行索引超出界限invalid cell selector: column X is out of range-列索引超出界限failed to style table cells: invalid dash_style-边框破折号样式无效object is not a table-对象ID未引用表object not found-找不到表对象IDpresentation not found-演示文稿不存在access denied to presentation-无权修改failed to style table cells-API在样式设置过程中出错
create_line
在幻灯片上创建线条或箭头。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 1,
"start_point": {"x": 10, "y": 10},
"end_point": {"x": 100, "y": 100},
"line_type": "STRAIGHT",
"start_arrow": "NONE",
"end_arrow": "ARROW",
"line_color": "#FF0000",
"line_weight": 2
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 否* | 1目标幻灯片的索引 |
slide_id |
string | 否* | 目标幻灯片的对象ID |
start_point |
object | 是 | 以点{x,y}开始坐标 |
end_point |
object | 是 | 以点{x,y}结束坐标 |
line_type |
string | 否 | 线型(直、曲、弯) |
start_arrow |
string | 否 | 开始处的箭头样式(无、箭头等) |
end_arrow |
string | 否 | 末尾的箭头样式(无、箭头等) |
line_color |
string | 否 | 行颜色十六进制字符串 |
line_weight |
number | No | 线宽(点数) |
line_dash |
string | 否 | 短跑风格(实心、短跑、DOT等) |
*要么 slide_index 或 slide_id 必须提供。
输出:
{
"object_id": "line_1234567890"
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 创建行的唯一标识符 |
线路类型:
STRAIGHT-直线连接CURVED-简单曲线ELBOW-斜角连接器线
箭头样式:
NONE-无箭头ARROW/FILL_ARROW-填充三角形箭头DIAMOND/FILL_DIAMOND-填充钻石OVAL/CIRCLE/FILL_CIRCLE-实心圆OPEN_ARROW-打开箭头OPEN_CIRCLE-开放式圆圈OPEN_DIAMOND-开放式钻石STEALTH_ARROW-窄填充箭头
特征:
- 自动处理起点/终点几何图形
- 支持任何方向的线条(包括反对角线)
- 在一次操作中应用样式和箭头
- 将用户友好的名称映射到API常量
示例:
创建一条简单的线:
{
"presentation_id": "abc123",
"slide_index": 1,
"start_point": {"x": 100, "y": 100},
"end_point": {"x": 300, "y": 100}
}
创建箭头:
{
"presentation_id": "abc123",
"slide_index": 1,
"start_point": {"x": 50, "y": 50},
"end_point": {"x": 250, "y": 150},
"end_arrow": "ARROW",
"line_weight": 3,
"line_color": "#0000FF"
}
创建弯曲连接器:
{
"presentation_id": "abc123",
"slide_index": 1,
"start_point": {"x": 100, "y": 100},
"end_point": {"x": 200, "y": 200},
"line_type": "CURVED",
"start_arrow": "OVAL",
"end_arrow": "ARROW",
"line_dash": "DOT"
}
错误:
start_point and end_point are required-缺少坐标invalid slide reference-未提供slide_index和slide_idslide not found-幻灯片不存在presentation not found-演示文稿不存在access denied-无权修改failed to create line-API错误
modify_shape
修改形状外观(填充、轮廓、阴影)。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "shape-123",
"properties": {
"fill_color": "#FF0000",
"outline_color": "#0000FF",
"outline_weight": 3,
"outline_dash": "DASH",
"shadow": true
}
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 要修改的形状的ID |
properties |
object | 是 | 要更新的属性 |
properties.fill_color |
string | 否 | 十六进制颜色或“透明” |
properties.outline_color |
string | 否 | 十六进制颜色或“透明” |
properties.outline_weight |
number | No | 轮廓权重(分) |
properties.outline_dash |
string | 否 | 短跑风格(实心、短跑、DOT等) |
properties.shadow |
boolean | 否 | 启用(真)或禁用(假)阴影 |
输出:
{
"object_id": "shape-123",
"updated_properties": ["fill_color", "outline_color", "shadow"]
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改对象的ID |
updated_properties |
array | 已更新的属性名称列表 |
特征:
- 修改填充和轮廓颜色,支持透明度
- 更改轮廓样式(粗细、破折号)
- 切换阴影可见性
- 更新应用于单个批处理请求中
示例:
将填充更改为绿色:
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"properties": {
"fill_color": "#00FF00"
}
}
使用虚线轮廓使其透明:
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"properties": {
"fill_color": "transparent",
"outline_color": "#000000",
"outline_weight": 2,
"outline_dash": "DASH"
}
}
错误:
no properties to update-Properties对象为空或缺失object not found-找不到对象IDaccess denied-无权修改failed to modify shape-API错误
apply_theme
将主题颜色从一个演示文稿应用到另一个演示稿。
输入:
{
"presentation_id": "target-presentation-id",
"theme_source": "presentation",
"source_presentation_id": "template-presentation-id"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 要应用主题的目标演示文稿 |
theme_source |
string | 是 | 源类型:“演示文稿”或“图库” |
theme_id |
string | 否 | 库主题ID(不支持-见下文) |
source_presentation_id |
string | 条件性 | 当theme_source为“presentation”时为必填项 |
输出:
{
"success": true,
"message": "Theme colors applied successfully from source presentation",
"updated_properties": ["color_dark1", "color_light1", "color_dark2", ...],
"source_master_id": "source-master-id",
"target_master_id": "target-master-id"
}
| 字段 | 类型 | 描述 |
|---|---|---|
success |
boolean | 操作是否成功 |
message |
string | 人类可读的结果消息 |
updated_properties |
array | 已更新的颜色类型列表 |
source_master_id |
string | 源主幻灯片的对象ID |
target_master_id |
string | 目标主幻灯片的对象ID |
特征:
- 将所有12种可编辑的主题颜色从源演示文稿复制到目标演示文稿
- 主题源不区分大小写(“presentation”、“presentation”)
- 更新目标演示文稿主幻灯片上的配色方案
支持的颜色类型: 复制了以下12种主题颜色类型:
DARK1,LIGHT1-主要深色/浅色DARK2,LIGHT2-次要深色/浅色ACCENT1通过ACCENT6-强调颜色HYPERLINK,FOLLOWED_HYPERLINK-链接颜色
API重要限制: 图库主题(谷歌幻灯片用户界面中的内置主题) 不能 通过Google Slides API应用。这是API的一个基本限制。要使用图库主题,请执行以下操作:
- 在Google幻灯片UI中手动应用它们(幻灯片>更改主题)
- 使用
theme_source: "presentation"从已经具有所需主题的演示文稿中复制颜色
示例:
从模板复制主题:
{
"presentation_id": "target-pres-id",
"theme_source": "presentation",
"source_presentation_id": "company-template-id"
}
错误:
gallery themes are not supported by the API-无法通过API应用库主题invalid theme source-必须是“图库”或“演示文稿”source_presentation_id is required-缺少演示文稿源的源IDno master slides found in source presentation-源没有主节点no master slides found in target presentation-目标没有主人no color scheme found in source presentation-源没有配色方案source presentation not found-源不存在presentation not found-目标不存在access denied-无权访问/修改
set_background
为一张或所有幻灯片设置背景(纯色、图像或渐变)。
输入:
{
"presentation_id": "abc123xyz",
"scope": "slide",
"slide_index": 1,
"background_type": "solid",
"color": "#FF0000"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
scope |
string | 是 | 单张幻灯片为“slide”,所有幻灯片为“all” |
slide_index |
number | 条件性 | 1基幻灯片索引(范围为“幻灯片”时需要) |
slide_id |
string | 条件性 | slide_index的替代方案 |
background_type |
string | 是 | “实心”、“图像”或“渐变” |
color |
string | 条件性 | 纯色背景的十六进制颜色(例如,“#FF0000”) |
image_base64 |
string | 条件 | 用于图像背景的Base64编码图像数据 |
start_color |
string | 条件 | 渐变开始的十六进制颜色 |
end_color |
string | 条件 | 渐变结束的十六进制颜色 |
angle |
number | No | 坡度角(0-360度),默认值为0 |
输出:
{
"success": true,
"message": "Solid background (#FF0000) applied successfully to slide",
"affected_slides": ["slide-1"]
}
| 字段 | 类型 | 描述 |
|---|---|---|
success |
boolean | 操作是否成功 |
message |
string | 人类可读的结果消息 |
affected_slides |
array | 已修改的幻灯片ID列表 |
背景类型:
| 类型 | 描述 | 必填参数 |
|---|---|---|
solid |
单色填充 | color |
image |
拉伸图像填充 | image_base64 |
gradient |
线性梯度填充 | start_color, end_color |
坡度角度:
- 0°=从左到右(默认)
- 90°=从上到下
- 180°=从右向左
- 270°=从下到上
特征:
- 范围和背景类型不区分大小写
- 对于图像背景,请将图像上传到谷歌云端硬盘
- 对于渐变背景,生成渐变PNG(API解决方法-不支持原生渐变)
- 自动使上传的图像可公开访问
示例:
在单张幻灯片上设置纯色:
{
"presentation_id": "abc123",
"scope": "slide",
"slide_index": 1,
"background_type": "solid",
"color": "#FF0000"
}
在所有幻灯片上设置纯色:
{
"presentation_id": "abc123",
"scope": "all",
"background_type": "solid",
"color": "#00FF00"
}
设置渐变背景:
{
"presentation_id": "abc123",
"scope": "slide",
"slide_index": 1,
"background_type": "gradient",
"start_color": "#FF0000",
"end_color": "#0000FF",
"angle": 90
}
错误:
invalid background type-必须是“实心”、“图像”或“渐变”scope must be 'slide' or 'all'-作用域值无效color is required for solid background-纯色缺失start_color and end_color are required for gradient-缺少渐变颜色gradient angle must be between 0 and 360-角度值无效slide_index or slide_id is required-范围为“幻灯片”时缺少幻灯片引用invalid image data-base64无效或图像格式未知failed to upload image-驱动器上传失败slide not found-幻灯片索引超出范围或找不到IDpresentation not found-演示文稿不存在access denied-无权修改
configure_footer
在演示文稿中配置页脚元素(幻灯片编号、日期、自定义文本)。
输入:
{
"presentation_id": "abc123xyz",
"show_slide_number": true,
"show_date": true,
"date_format": "January 2, 2006",
"footer_text": "Company Confidential",
"apply_to": "all"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
show_slide_number |
boolean | 否 | 启用/禁用幻灯片编号 |
show_date |
boolean | 否 | 启用/禁用日期显示 |
date_format |
string | 否 | Go日期格式字符串(默认值:“2006年1月2日”) |
footer_text |
string | 否 | 自定义页脚文本(空=不更改,“”=清除) |
apply_to |
string | 否 | “全部”、“title_slides_only”或“exclude_title_slides”(默认值:“全部”) |
输出:
{
"success": true,
"message": "Footer configuration updated successfully (slide numbers: 3, dates: 3, footers: 3)",
"updated_slide_numbers": 3,
"updated_dates": 3,
"updated_footers": 3,
"affected_slide_ids": ["slide-1", "slide-2", "slide-3"],
"applied_to": "all"
}
特征:
- 通过将占位符文本设置为“#”或清除它来启用/禁用幻灯片编号
- 使用可自定义的Go日期格式设置日期
- 设置自定义页脚文本或用空字符串清除它
- 应用于所有幻灯片、仅标题幻灯片或排除标题幻灯片
- 必须至少提供show_slide_number、show_date或footer_text中的一个
应用于选项:
| 选项 | 描述 |
|---|---|
all |
应用于所有幻灯片(默认) |
title_slides_only |
仅适用于标题幻灯片(title、title_SLIDE、SECTION_HEADER布局) |
exclude_title_slides |
适用于除标题幻灯片之外的所有幻灯片 |
API重要限制: 页脚占位符必须存在于演示文稿的主/布局中。此工具无法创建占位符,它只能修改现有的占位符。
错误:
invalid apply_to value-必须是“全部”、“title_slides_only”或“exclude_title_slides”no footer changes specified-提供show_slide_number、show_date或foot_text中的至少一个no footer placeholders found-演示文稿的主题中没有页脚占位符presentation not found-演示文稿不存在access denied-无权修改
transform_object
移动、调整大小或旋转任何对象。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "shape-123",
"position": {"x": 100, "y": 100},
"size": {"width": 200, "height": 100},
"rotation": 45,
"scale_proportionally": true
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 要转换的对象的ID |
position |
object | 否 | 点{x,y}中的新位置 |
size |
object | 否 | 以点为单位的新大小{宽度、高度} |
rotation |
number | No | 旋转角度(度)(0-360) |
scale_proportionally |
boolean | 否 | 调整大小时是否按比例缩放(默认值:true) |
输出:
{
"position": {"x": 100, "y": 100},
"size": {"width": 200, "height": 100},
"rotation": 45
}
| 字段 | 类型 | 描述 |
|---|---|---|
position |
object | 最终点数位置 |
size |
object | 最终大小(以点为单位) |
rotation |
number | 最终旋转度数 |
特征:
- 将对象移动到绝对坐标
- 使用可选的比例缩放调整对象大小
- 将对象旋转到特定角度
- 自动处理复杂的变换数学
示例:
移动对象:
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"position": {"x": 50, "y": 50}
}
调整大小(双倍宽度):
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"size": {"width": 400}
}
旋转45度:
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"rotation": 45
}
错误:
object not found-找不到对象IDcannot resize object with unknown base size-无法确定缩放的原始大小access denied-无权修改failed to transform object-API错误
change_z_order
更改幻灯片上对象的z顺序(分层)。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "shape-123",
"action": "bring_to_front"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 是 | 要重新排序的对象的ID |
action |
string | Yes | Z顺序操作(请参阅操作表) |
行动:
| 动作 | 描述 |
|---|---|
bring_to_front |
将对象移动到堆栈顶部(前面) |
send_to_back |
将对象移动到堆栈底部(向后) |
bring_forward |
将对象向上移动一层 |
send_backward |
将对象向下移动一层 |
输出:
{
"object_id": "shape-123",
"action": "bring_to_front",
"new_z_order": 2,
"total_layers": 3
}
| 字段 | 类型 | 描述 |
|---|---|---|
object_id |
string | 修改对象的ID |
action |
string | 执行的操作(小写) |
new_z_order |
number | 新的0基位置(0=最后面) |
total_layers |
number | 幻灯片上的对象总数 |
特征:
- 动作名称不区分大小写
- 更改后返回位置信息
- 分组对象不能更改z顺序(API限制)
示例:
带到前面:
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"action": "bring_to_front"
}
向后移动一层:
{
"presentation_id": "abc123",
"object_id": "shape-xyz",
"action": "send_backward"
}
错误:
invalid z-order action-指定的操作无效cannot change z-order of grouped objects-对象位于组内object not found-找不到对象IDaccess denied-无权修改failed to change z-order-API错误
group_objects
对幻灯片上的对象进行分组或取消分组。
输入:
{
"presentation_id": "abc123xyz",
"action": "group",
"object_ids": ["shape-1", "shape-2", "shape-3"]
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
action |
string | 是 | 要执行的操作: group 或 ungroup |
object_ids |
array | For group | 要分组的对象ID数组(至少2个) |
object_id |
string | 用于取消分组 | 要取消分组的组的ID |
行动:
| 动作 | 描述 |
|---|---|
group |
将多个对象组合到一个组中 |
ungroup |
将组拆分为单个对象 |
输出(集体行动):
{
"action": "group",
"group_id": "group_1234567890"
}
输出(取消分组操作):
{
"action": "ungroup",
"object_ids": ["shape-1", "shape-2", "shape-3"]
}
| 字段 | 类型 | 描述 |
|---|---|---|
action |
string | 执行的操作 |
group_id |
string | 已创建组的对象ID(用于组操作) |
object_ids |
array | 未分组对象的ID(用于取消分组操作) |
特征:
- 动作名称不区分大小写
- 至少需要2个对象进行分组
- 所有对象必须位于同一幻灯片上
- 验证对象是否可以分组
无法分组的对象:
- 表格
- 视频
- 占位符形状(标题、正文等)
- 对象已在另一个组中
示例:
组对象:
{
"presentation_id": "abc123",
"action": "group",
"object_ids": ["shape-1", "shape-2"]
}
取消组分组:
{
"presentation_id": "abc123",
"action": "ungroup",
"object_id": "group_1234567890"
}
错误:
invalid group action-操作必须是“组”或“取消组”at least two objects are required to group-至少需要2个对象all objects must be on the same page-不同幻灯片上的对象object is not a group-尝试取消对非组对象的分组object cannot be grouped-不支持对象类型(表、视频、占位符)object not found-找不到对象IDaccess denied-无权修改failed to group/ungroup objects-API错误
delete_object
从演示文稿中删除一个或多个对象。
输入:
{
"presentation_id": "abc123xyz",
"object_id": "shape-xyz"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
object_id |
string | 否* | 要删除的单个对象ID |
multiple |
array | 否* | 用于批量删除的对象ID数组 |
*至少一个 object_id 或 multiple 是必需的。两者可以一起提供。
输出:
{
"deleted_count": 3,
"deleted_ids": ["shape-1", "shape-2", "shape-3"],
"not_found_ids": ["shape-4"]
}
| 字段 | 类型 | 描述 |
|---|---|---|
deleted_count |
number | 删除的对象数 |
deleted_ids |
array | 已删除对象ID列表 |
not_found_ids |
array | 找不到的对象ID(可选) |
特征:
- 批量删除单个对象或多个对象
- 两者
object_id和multiple可以组合 - 自动消除对象ID的重复
- 部分成功:删除已找到的对象,未单独找到报告
- 在任何地方查找对象(幻灯片、母版、布局、嵌套在组中)
示例:
删除单个对象:
{
"presentation_id": "abc123",
"object_id": "shape-xyz"
}
删除多个对象:
{
"presentation_id": "abc123",
"multiple": ["shape-1", "shape-2", "image-1"]
}
同时删除(所有唯一ID):
{
"presentation_id": "abc123",
"object_id": "shape-1",
"multiple": ["shape-2", "shape-3"]
}
错误:
no objects specified for deletion-既没有提供object_id也没有提供multiplenone of the specified objects were found-未找到所有对象presentation not found-演示文稿不存在access denied-无权修改failed to delete object-API错误
set_transition
⚠️ API限制: 此工具返回错误,因为Google Slides API不支持以编程方式设置幻灯片转换。
输入:
{
"presentation_id": "abc123xyz",
"slide_index": 1,
"transition_type": "FADE",
"duration": 0.5
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
slide_index |
integer | 否 | 1基幻灯片索引(使用此OR slide_id,或对所有幻灯片省略) |
slide_id |
string | 否 | 幻灯片对象ID(Slide_index的替代品) |
transition_type |
string | 是 | 过渡效果类型(见下表) |
duration |
number | No | 持续时间(秒)(0-10) |
转换类型(已验证,但API不支持):
NONE-无过渡FADE-褪色效果SLIDE_FROM_RIGHT,SLIDE_FROM_LEFT,SLIDE_FROM_TOP,SLIDE_FROM_BOTTOM-幻灯片效果FLIP,CUBE,GALLERY,ZOOM,DISSOLVE-其他影响
输出: 该工具总是为有效输入返回一个错误,因为Google Slides API不支持转换。
API限制详细信息:
谷歌幻灯片API SlideProperties 对象仅包含:
isSkipped-演示模式下是否跳过幻灯片layoutObjectId-布局参考masterObjectId-主参考notesPage-演讲者笔记
API中没有与转换相关的属性。
解决方法:
- 使用谷歌幻灯片用户界面(幻灯片>过渡)
- 使用Google Apps脚本
SlidesApp.Slide.setTransition()方法
错误:
slide transitions are not supported by the Google Slides API-所有有效输入的预期错误invalid transition type-转换类型为空或不受支持invalid transition duration-持续时间为负或超过10秒presentation_id is required-空演示文稿ID
list_comments
在演示文稿中列出所有评论,并附上回复和锚点信息。
输入:
{
"presentation_id": "abc123xyz",
"include_resolved": false
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
include_resolved |
boolean | 否 | 包含已解析的注释(默认值:false) |
输出:
{
"presentation_id": "abc123xyz",
"comments": [
{
"comment_id": "AAAABxyz",
"author": {
"display_name": "John Doe",
"email_address": "john@example.com",
"photo_link": "https://..."
},
"content": "This slide needs more details",
"html_content": "<p>This slide needs more details</p>",
"anchor_info": "{\"r\":\"headings\",\"a\":[{\"startIndex\":5}]}",
"replies": [
{
"reply_id": "AAAACxyz",
"author": {
"display_name": "Jane Doe",
"email_address": "jane@example.com"
},
"content": "I'll add more content",
"created_time": "2024-01-15T11:00:00Z"
}
],
"resolved": false,
"created_time": "2024-01-15T10:00:00Z",
"modified_time": "2024-01-15T11:00:00Z"
}
],
"total_count": 5,
"unresolved_count": 3,
"resolved_count": 2
}
特征:
- 列出使用驱动器API的所有评论(评论存储在驱动器中,而不是幻灯片API中)
- 默认情况下,只返回未解决的注释
- 包括每条评论的所有回复以及作者信息
- 为定位注释提供JSON字符串形式的锚点信息
- 自动处理分页以检索所有评论
- 返回统计信息:总计数、未解析计数、已解析计数
错误:
presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied-无权访问演示文稿drive API error-其他驱动器API错误
add_comment
向演示文稿添加注释,并可选择锚定到特定对象或幻灯片。
输入:
{
"presentation_id": "abc123xyz",
"content": "This slide needs more work",
"anchor_object_id": "shape-xyz",
"anchor_page_index": 2
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
content |
string | 是 | 评论文本内容 |
anchor_object_id |
string | 否 | 要锚定注释的对象ID |
anchor_page_index |
integer | 否 | 用于锚定评论的幻灯片索引(从0开始) |
输出:
{
"comment_id": "AAAABxyz",
"presentation_id": "abc123xyz",
"content": "This slide needs more work",
"anchor_info": "{\"r\":\"content\",\"a\":[{\"n\":\"objectId\",\"v\":\"shape-xyz\"}]}",
"created_time": "2024-01-15T10:00:00Z"
}
锚行为:
- 如果
anchor_object_id如果提供了,则评论将锚定到该对象 - 如果
anchor_page_index如果提供了(并且没有对象锚点),则评论将锚定到该幻灯片上 - 如果两者都提供,
anchor_object_id优先 - 如果两者都没有提供,则会在演示文稿中添加评论,而不需要特定的锚点
- 页面索引从0开始(幻灯片1=索引0,幻灯片2=索引1,以此类推)
特征:
- 通过驱动器API创建评论(评论由驱动器管理,而不是幻灯片API)
- 支持通过对象ID锚定到特定对象(形状、图像等)
- 支持通过基于0的页面索引锚定到特定幻灯片
- 返回创建的评论的ID以供将来参考
- 在输出中包含创建的时间戳
错误:
comment content is required-提供的内容为空presentation_id is required-空演示文稿IDpresentation not found-演示文稿不存在access denied-无权对演示文稿发表评论drive API error-其他驱动器API错误
manage_comment
回复、解决、取消解决或删除演示文稿中的评论。
输入:
{
"presentation_id": "abc123xyz",
"comment_id": "AAAABxyz",
"action": "reply",
"content": "Thanks for the feedback!"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
comment_id |
string | 是 | 要管理的注释ID |
action |
string | 是 | 要执行的操作: reply, resolve, unresolve,或 delete |
content |
string | 用于回复 | 回复文本(仅需要 reply 行动) |
输出:
{
"presentation_id": "abc123xyz",
"comment_id": "AAAABxyz",
"action": "reply",
"reply_id": "AAAACdef",
"success": true,
"message": "Reply added successfully"
}
行动:
| 动作 | 描述 |
|---|---|
reply |
为评论添加回复(需要 content 参数) |
resolve |
将评论标记为已解决 |
unresolve |
重新打开已解决的评论 |
delete |
完全删除评论 |
特征:
- 通过驱动器API管理评论(评论存储在驱动器中,而不是幻灯片API中)
- 动作名称不区分大小写(
reply,REPLY,Reply所有工作) - Reply操作返回创建的回复ID
- Resolve/unresolve更新评论的已解决状态
- 删除永久删除评论
错误:
comment_id is required-提供的评论ID为空invalid action-操作不是回复、解决、取消解决或删除content is required for reply action-未提供用于回复操作的内容comment not found-评论不存在presentation_id is required-空演示文稿IDaccess denied-无权管理评论drive API error-其他驱动器API错误
add_video-嵌入视频create_table-插入表格modify_table_structure-在表中添加/删除行和列merge_cells-合并或取消合并表单元格modify_table_cell-修改表格单元格内容和样式style_table_cells-将视觉样式(背景色、边框)应用于表格单元格
造型和主题
apply_theme-应用演示主题set_background-配置背景configure_footer-配置幻灯片页脚(数字、日期、文本)set_transition-添加幻灯片过渡add_animation-创建对象动画manage_animations-管理动画顺序(列表、重新排序、修改、删除)manage_speaker_notes-获取、设置、附加或清除演讲者笔记
协作
list_comments-在演示文稿中列出所有评论,并附上回复和锚点信息add_comment-使用可选对象/幻灯片锚定向演示文稿添加注释manage_comment-回复、解决、取消解决或删除评论
翻译
translate_presentation-使用Google Cloud Translation API翻译演示文稿中的文本
批量操作
batch_update-在单个API调用中执行多个操作以提高效率
translate_presentation
使用Google Cloud Translation API翻译演示文稿中的文本。
输入:
{
"presentation_id": "abc123xyz",
"target_language": "fr",
"source_language": "en",
"scope": "all"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
target_language |
string | 是 | ISO 639-1语言代码(例如。, fr, es, de, ja) |
source_language |
string | 否 | 源语言代码(如果省略,则自动检测) |
scope |
string | 否 | 翻译范围: all (默认), slide,或 object |
slide_index |
integer | 范围=幻灯片 | 1基于幻灯片索引 |
slide_id |
string | 范围=slide | slide_index的替代品 |
object_id |
string | 用于范围=对象 | 要转换的对象ID |
输出:
{
"presentation_id": "abc123xyz",
"target_language": "fr",
"source_language": "auto-detected",
"translated_count": 15,
"affected_slides": [1, 2, 3],
"translated_elements": [
{
"slide_index": 1,
"object_id": "shape_123",
"object_type": "TEXT_BOX",
"original_text": "Hello World",
"translated_text": "Bonjour le monde"
}
]
}
范围选项:
| 范围 | 描述 |
|---|---|
all |
翻译整个演示文稿中的所有文本(默认) |
slide |
仅翻译特定幻灯片上的文本(需要 slide_index 或 slide_id) |
object |
仅翻译特定对象中的文本(需要 object_id) |
特征:
- 使用Google Cloud Translation API进行高质量翻译
- 批量翻译所有文本元素以提高效率
- 支持源语言的自动检测
- 翻译形状、文本框和演讲者笔记中的文本
- 替换文本内容时保留格式
- 返回包含前后文本的翻译元素的详细列表
错误:
target_language is required-未指定目标语言invalid scope-范围必须是“全部”、“幻灯片”或“对象”slide_index or slide_id is required when scope is 'slide'-缺少幻灯片参考object_id is required when scope is 'object'-缺少对象IDno translatable text found-在指定范围内找不到文本translation API error-Google云翻译API错误presentation not found-演示文稿不存在access denied-无权修改演示文稿
batch_update
在单个API调用中执行多个幻灯片操作以提高效率。
输入:
{
"presentation_id": "abc123xyz",
"operations": [
{
"tool_name": "add_slide",
"parameters": {"position": 1, "layout": "BLANK"}
},
{
"tool_name": "add_text_box",
"parameters": {
"slide_index": 1,
"text": "Hello World",
"size": {"width": 300, "height": 100},
"position": {"x": 100, "y": 50}
}
}
],
"on_error": "stop"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
presentation_id |
string | 是 | 谷歌幻灯片演示文稿ID |
operations |
array | Yes | 要执行的操作数组 |
operations[].tool_name |
string | 是 | 要执行的工具的名称 |
operations[].parameters |
object | 是 | 工具特定参数 |
on_error |
string | 否 | 错误处理模式: stop (默认), continue,或 rollback |
输出:
{
"presentation_id": "abc123xyz",
"total_operations": 2,
"success_count": 2,
"failure_count": 0,
"results": [
{
"index": 0,
"tool_name": "add_slide",
"success": true,
"result": {"slide_id": "slide_123", "slide_index": 1}
},
{
"index": 1,
"tool_name": "add_text_box",
"success": true,
"result": {"object_id": "textbox_456"}
}
],
"batch_optimized": true,
"api_call_count": 1
}
关于错误模式:
| 模式 | 描述 |
|---|---|
stop |
在第一个错误时停止处理(默认)。跳过其余操作。 |
continue |
继续处理所有操作。收集错误并在最后返回。 |
rollback |
出现第一个错误时停止。对于原子批处理操作,整个批处理一起失败。 |
支持的操作(可批处理): 这些操作组合成一个幻灯片API,以提高效率:
| 工具名称 | 描述 |
|---|---|
add_slide |
在演示文稿中添加新幻灯片 |
delete_slide |
从演示文稿中删除幻灯片 |
add_text_box |
在幻灯片中添加文本框 |
modify_text |
修改形状中的文本内容 |
delete_object |
删除一个或多个对象 |
create_shape |
在幻灯片上创建形状 |
transform_object |
移动、调整大小或旋转对象 |
style_text |
将样式应用于文本 |
create_bullet_list |
将文本转换为项目符号列表 |
create_numbered_list |
将文本转换为编号列表 |
支持的操作(非批处理): 这些操作需要单独的API调用,但仍受支持:
| 工具名称 | 描述 |
|---|---|
add_image |
添加图像(需要上传驱动器) |
add_video |
从YouTube或Drive添加视频 |
replace_image |
替换现有映像 |
set_background |
设置幻灯片背景 |
translate_presentation |
翻译演示文稿文本 |
特征:
- 将兼容的操作组合到单个Slides API BatchUpdate调用中
- 维护相关操作的操作顺序
- 按操作成功/失败状态报告
- 跟踪实际API调用计数与操作计数
- 支持三种错误处理模式
- 返回每个操作的详细结果
错误:
no operations provided-操作数组为空invalid on_error value-onerror必须为“停止”、“继续”或“回滚”unsupported tool name-批处理操作不支持工具名称invalid operation-操作的结构或参数无效presentation not found-演示文稿不存在access denied-无权修改演示文稿
API费率限制和配额
Google幻灯片API配额
| 配额 | 限额 | 备注 |
|---|---|---|
| 读取请求 | 300/分钟 | 每个用户每个项目 |
| 写入请求 | 60/分钟 | 每个用户每个项目 |
| BatchUpdate请求 | 60/分钟 | 每个用户每个项目 |
| 每日配额 | 变化 | 基于项目配额分配 |
Google Drive API配额
| 配额 | 限额 | 备注 |
|---|---|---|
| 每100秒查询次数 | 20000次 | 每个项目 |
| 每位用户每100秒查询次数 | 1000 | 每位用户 |
| 每日使用限制 | 可配置 | 在GCP控制台中 |
谷歌翻译API配额
| 配额 | 限额 | 备注 |
|---|---|---|
| 每日角色数 | 500000 | 免费等级 |
| 每100秒字符数 | 10000 | 每个项目 |
MCP服务器速率限制
服务器实现了自己的速率限制以防止滥用:
| 设置 | 默认值 | 说明 |
|---|---|---|
| 每秒请求数 | 10 | 令牌桶充值率 |
| 突发大小 | 20 | 最大并发请求数 |
| 每个端点的限制 | 可配置 | 可以为每个端点设置不同的限制 |
处理速率限制错误
当超过速率限制时:
- HTTP 429响应:服务器返回
429 Too Many Requests - 标头后重试:包含重试前等待的秒数
- X-RateLimit接头:显示当前配额状态:
X-RateLimit-Limit:允许的最大请求数X-RateLimit-Remaining:当前窗口中剩余的请求X-RateLimit-Reset:限制重置时的Unix时间戳
建议客户行为:
# Example retry logic
import time
def call_with_retry(request, max_retries=5):
for attempt in range(max_retries):
response = make_request(request)
if response.status_code == 429:
retry_after = int(response.headers.get('Retry-After', 60))
time.sleep(retry_after)
continue
return response
raise Exception("Max retries exceeded")
配额管理的最佳实践
- 使用批处理操作:使用以下命令组合多个操作
batch_update以减少API调用 - 启用缓存:服务器缓存演示文稿和权限以减少API调用
- 实施回退:重试失败的请求时使用指数回退
- 监视器使用情况:跟踪Google云控制台中API的使用情况
- 请求配额增加:如果需要,在GCP控制台中请求更高的配额
故障排除
常见问题
身份验证错误
问题:API请求上的“401未授权”
- 原因:API密钥无效或过期
- 解决方案:
- 通过重新验证
/auth端点 - 确保传入API密钥
Authorization: Bearer <api_key>头球 - 检查Firestore中是否存在API密钥
- 通过重新验证
问题:“OAuth2回调错误”
- 原因:OAuth2凭据无效或重定向URI不匹配
- 解决方案:
- 在密钥管理器中验证OAuth2凭据
- 确保重定向URI在Google Cloud Console OAuth配置中匹配
- 检查是否启用了所需的作用域
权限错误
问题:演示操作中出现“403拒绝访问”
- 原因:用户无权访问或修改演示文稿
- 解决方案:
- 验证用户是否可以访问Google Drive中的演示文稿
- 对于写入操作,确保用户具有编辑者角色(而不是查看者/评论者)
- 检查演示文稿是否位于访问受限的共享驱动器中
问题:“找不到演示文稿”
- 原因:演示文稿ID无效或已删除演示文稿
- 解决方案:
- 验证演示文稿ID是否正确(从URL提取:
docs.google.com/presentation/d/<ID>/edit) - 检查演示文稿是否已移至回收站
- 确保用户可以访问演示文稿
- 验证演示文稿ID是否正确(从URL提取:
API错误
问题:“429请求太多”
- 原因:超出费率限制
- 解决方案:
- 等待中指定的持续时间
Retry-After头球 - 降低请求频率
- 使用批处理操作组合多个调用
- 检查Google Cloud Console的配额状态
- 等待中指定的持续时间
问题:“500内部服务器错误”
- 原因:Google API暂时故障或服务器问题
- 解决方案:
- 使用指数回退重试(启用重试逻辑后自动重试)
- 检查Google Cloud状态仪表板是否出现中断
- 查看服务器日志以了解具体的错误详细信息
问题:“503服务不可用”
- 原因:Google API暂时不可用
- 解决方案:
- 等待并重试(已配置自动重试)
- 检查Google Cloud状态以了解维护窗口
工具特定错误
问题:“set_transition返回错误”
- 原因:Google Slides API不支持以编程方式设置转换
- 解决方案:直接使用谷歌幻灯片UI(幻灯片>过渡)
问题:“add_animation返回错误”
- 原因:Google Slides API不支持以编程方式添加动画
- 解决方案:直接使用谷歌幻灯片UI(插入>动画)
问题:“带有库源的apply_theme失败”
- 原因:Google Slides API不支持应用库主题
- 解决方案:
- 使用主题源
presentation从现有演示文稿复制 - 使用Google幻灯片UI应用库主题
- 使用主题源
问题:“图像上传失败”
- 原因:图像数据无效或格式不受支持
- 解决方案:
- 确保图像是base64编码的
- 使用支持的格式:PNG、JPEG、GIF、WebP、BMP
- 检查图像数据是否损坏
问题:“表单元格索引超出范围”
- 原因:行或列索引超出表维度
- 解决方案:
- 使用
get_object首先验证表尺寸 - 确保使用基于0的索引(第0行第0列是第一个单元格)
- 使用
部署问题
问题:“云运行部署失败”
- 原因:生成错误或配置问题
- 解决方案:
- 检查云构建日志中的构建错误
- 验证本地生成的Dockerfile:
docker build -t test . - 确保机密管理器中存在所有必需的机密
- 检查Cloud Run服务帐户的IAM权限
问题:“地形应用失败”
- 原因:缺少API、权限或配置错误
- 解决方案:
- 跑
terraform init初始化 - 检查
config.yaml具有有效的项目ID - 确保已启用云资源管理器API
- 验证用户在项目上具有所有者/编辑者角色
- 跑
问题:“健康检查失败”
- 原因:服务器未启动或端口配置错误
- 解决方案:
- 在Cloud Run控制台中检查服务器日志
- 验证PORT环境变量是否设置正确
- 本地测试:
curl http://localhost:8080/health
调试提示
- 启用详细日志记录:在环境中将日志级别设置为DEBUG
- 检查请求/响应:使用
curl -v查看完整的HTTP标头 - 先在本地测试:使用运行服务器
make run部署前 - 验证输入:使用JSON模式验证工具参数
- 检查API配额:监控Google Cloud控制台中的使用情况
获取帮助
配置
环境变量
| 变量 | 必填 | 默认 | 描述 |
|---|---|---|---|
PORT |
没有 | 8080 | HTTP服务器端口 |
GCP_PROJECT_ID |
是 | - | 谷歌云项目ID |
OAUTH_CLIENT_ID |
是 | - | OAuth2客户端ID(来自生产中的Secret Manager) |
OAUTH_CLIENT_SECRET |
是 | - | OAuth2客户端机密(来自生产中的secret Manager) |
LOG_LEVEL |
否 | 信息 | 日志记录级别(调试、信息、警告、错误) |
RATE_LIMIT_RPS |
无 | 10 | 每秒速率限制请求 |
RATE_LIMIT_BURST |
否 | 20 | 速率限制突发大小 |
CACHE_TTL_MINUTES |
无 | 5 | 缓存演示文稿和权限的TTL |
TOKEN_CACHE_TTL_MINUTES |
否 | 55 | 缓存访问令牌的TTL |
地形配置
编辑 terraform/config.yaml 要自定义部署,请执行以下操作:
gcp:
project_id: "your-project-id"
location: "europe-west1"
resources:
cloud_run:
cpu: "1"
memory: "512Mi"
min_instances: 0
max_instances: 10
timeout: "300s"
parameters:
log_level: "INFO"
rate_limit_rps: "10"
rate_limit_burst: "20"
OAuth2范围
服务器请求这些OAuth2作用域:
| 范围 | 目的 |
|---|---|
https://www.googleapis.com/auth/presentations |
完全访问幻灯片API |
https://www.googleapis.com/auth/drive |
对驱动器API的完全访问(搜索、复制、权限) |
https://www.googleapis.com/auth/cloud-translation |
访问翻译API |
许可证
MIT许可证
