ClawSkills logoClawSkills

Google Forms

与托管 OAuth 集成的 Google Forms API。创建表单、添加问题并检索回复。当用户想要与 Google For 交互时,请使用此技能

介绍

# Google Forms

通过托管的 OAuth 身份验证访问 Google 表单 API。创建表单、添加问题并获取回复。

## 快速开始

```bash # Get form python <<'EOF' import urllib.request, os, json req = urllib.request.Request('https://gateway.maton.ai/google-forms/v1/forms/{formId}') req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}') print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2)) EOF ```

## 基础 URL

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

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

## 身份验证

所有请求都需要在 Authorization 标头中包含 Maton API 密钥:

``` Authorization: Bearer $MATON_API_KEY ```

**环境变量:** 将您的 API 密钥设置为 `MATON_API_KEY`:

```bash export MATON_API_KEY="YOUR_API_KEY" ```

### 获取 API 密钥

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

## 连接管理

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

### 列出连接

```bash python <<'EOF' import urllib.request, os, json req = urllib.request.Request('https://ctrl.maton.ai/connections?app=google-forms&status=ACTIVE') req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}') print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2)) EOF ```

### 创建连接

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

### 获取连接

```bash python <<'EOF' import urllib.request, os, json req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}') req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}') print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2)) EOF ```

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

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

### 删除连接

```bash python <<'EOF' import urllib.request, os, json req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE') req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}') print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2)) EOF ```

### 指定连接

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

```bash python <<'EOF' import urllib.request, os, json req = urllib.request.Request('https://gateway.maton.ai/google-forms/v1/forms/{formId}') req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}') req.add_header('Maton-Connection', '21fd90f9-5935-43cd-b6c8-bde9d915ca80') print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2)) EOF ```

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

## API 参考

### 获取表单

```bash GET /google-forms/v1/forms/{formId} ```

### 创建表单

```bash POST /google-forms/v1/forms Content-Type: application/json

{ "info": { "title": "Customer Feedback Survey" } } ```

### 批量更新表单

```bash POST /google-forms/v1/forms/{formId}:batchUpdate Content-Type: application/json

{ "requests": [ { "createItem": { "item": { "title": "What is your name?", "questionItem": { "question": { "required": true, "textQuestion": {"paragraph": false} } } }, "location": {"index": 0} } } ] } ```

### 列出回复

```bash GET /google-forms/v1/forms/{formId}/responses ```

### 获取回复

```bash GET /google-forms/v1/forms/{formId}/responses/{responseId} ```

## 常见 batchUpdate 请求

### 创建文本问题

```json { "createItem": { "item": { "title": "Question text", "questionItem": { "question": { "required": true, "textQuestion": {"paragraph": false} } } }, "location": {"index": 0} } } ```

### 创建选择题

```json { "createItem": { "item": { "title": "Select an option", "questionItem": { "question": { "choiceQuestion": { "type": "RADIO", "options": [ {"value": "Option A"}, {"value": "Option B"} ] } } } }, "location": {"index": 0} } } ```

### 创建量表问题

```json { "createItem": { "item": { "title": "Rate your experience", "questionItem": { "question": { "scaleQuestion": { "low": 1, "high": 5, "lowLabel": "Poor", "highLabel": "Excellent" } } } }, "location": {"index": 0} } } ```

## 问题类型

- `textQuestion` - 简短文本或段落文本 - `choiceQuestion` - 单选、复选框或下拉菜单 - `scaleQuestion` - 线性量表 - `dateQuestion` - 日期选择器 - `timeQuestion` - 时间选择器

## 代码示例

### JavaScript

```javascript const response = await fetch( 'https://gateway.maton.ai/google-forms/v1/forms/FORM_ID/responses', { headers: { 'Authorization': `Bearer ${process.env.MATON_API_KEY}` } } ); ```

### Python

```python import os import requests

response = requests.get( f'https://gateway.maton.ai/google-forms/v1/forms/FORM_ID/responses', headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'} ) ```

## 注意事项

- 表单 ID 位于表单 URL 中 - 使用 `updateMask` 指定要更新的字段 - 位置索引从 0 开始 - 重要:使用 curl 命令时,如果 URL 包含方括号,请使用 `curl -g` 以禁用 glob 解析 - 重要:当将 curl 输出通过管道传递给 `jq` 或其他命令时,在某些 shell 环境中,`$MATON_API_KEY` 等环境变量可能无法正确展开。您可能会在通过管道传递时遇到“Invalid API key”(无效的 API 密钥)错误。

## 错误处理

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

### 故障排除:API 密钥问题

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

```bash echo $MATON_API_KEY ```

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

```bash python <<'EOF' import urllib.request, os, json req = urllib.request.Request('https://ctrl.maton.ai/connections') req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}') print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2)) EOF ```

### 故障排除:无效的应用名称

1. 确保您的 URL 路径以 `google-forms` 开头。例如:

- 正确:`https://gateway.maton.ai/google-forms/v1/forms/{formId}` - 错误:`https://gateway.maton.ai/forms/v1/forms/{formId}`

## 资源

- [Forms API 概览](https://developers.google.com/workspace/forms/api/reference/rest) - [获取表单](https://developers.google.com/workspace/forms/api/reference/rest/v1/forms/get) - [创建表单](https://developers.google.com/workspace/forms/api/reference/rest/v1/forms/create) - [批量更新](https://developers.google.com/workspace/forms/api/reference/rest/v1/forms/batchUpdate) - [列出回复](https://developers.google.com/workspace/forms/api/reference/rest/v1/forms.responses/list) - [Maton 社区](https://discord.com/invite/dBfFAcefs2) - [Maton 支持](mailto:[email protected])

更多产品