Google Forms
2026-03-28
新闻来源:网淘吧
围观:15
电脑广告
手机广告
Google Forms
通过托管的OAuth身份验证访问Google Forms API。创建表单、添加问题并获取响应。
快速入门
# 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 Forms API端点路径。网关将请求代理到forms.googleapis.com并自动注入您的OAuth令牌。
身份验证
所有请求都需要在Authorization头部中包含Maton API密钥:
Authorization: Bearer $MATON_API_KEY
环境变量:将您的API密钥设置为MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
获取您的API密钥
复制您的API密钥
请前往以下地址管理您的Google OAuth连接https://ctrl.maton.ai。
列出连接
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
创建连接
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
获取连接
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
响应:
{
"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授权。
删除连接
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 Forms连接,请通过Maton-Connection请求头来指定要使用哪一个:
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参考
获取表单
GET /google-forms/v1/forms/{formId}
创建表单
POST /google-forms/v1/forms
Content-Type: application/json
{
"info": {
"title": "Customer Feedback Survey"
}
}
批量更新表单
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}
}
}
]
}
列出回复
GET /google-forms/v1/forms/{formId}/responses
获取回复
GET /google-forms/v1/forms/{formId}/responses/{responseId}
常见的batchUpdate请求
创建文本题
{
"createItem": {
"item": {
"title": "Question text",
"questionItem": {
"question": {
"required": true,
"textQuestion": {"paragraph": false}
}
}
},
"location": {"index": 0}
}
}
创建选择题
{
"createItem": {
"item": {
"title": "Select an option",
"questionItem": {
"question": {
"choiceQuestion": {
"type": "RADIO",
"options": [
{"value": "Option A"},
{"value": "Option B"}
]
}
}
}
},
"location": {"index": 0}
}
}
创建量表题
{
"createItem": {
"item": {
"title": "Rate your experience",
"questionItem": {
"question": {
"scaleQuestion": {
"low": 1,
"high": 5,
"lowLabel": "Poor",
"highLabel": "Excellent"
}
}
}
},
"location": {"index": 0}
}
}
问题类型
文本题- 短文本或段落文本选择题- 单选、多选或下拉选择量表题- 线性量表日期题- 日期选择器时间题- 时间选择器
代码示例
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
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命令时,请使用
curl -g当URL中包含括号以禁用通配符解析时 - 重要提示:当将curl输出通过管道传输到
jq或其他命令时,在某些shell环境中,像$MATON_API_KEY这样的环境变量可能无法正确展开。通过管道传输时,您可能会遇到“无效API密钥”错误。
错误处理
| 状态码 | 含义 |
|---|---|
| 400 | 缺少Google Forms连接 |
| 401 | Maton API密钥无效或缺失 |
| 429 | 请求频率受限(每个账户每秒10次请求) |
| 4xx/5xx | 来自Google Forms API的透传错误 |
故障排除:API密钥问题
- 请检查
MATON_API_KEY环境变量是否已设置:
echo $MATON_API_KEY
- 通过列出连接来验证API密钥是否有效:
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
故障排除:无效应用名称
- 请确保您的URL路径以
google-forms开头。例如:
- 正确示例:
https://gateway.maton.ai/google-forms/v1/forms/{表单ID} - 错误示例:
https://gateway.maton.ai/forms/v1/forms/{表单ID}
相关资源
文章底部电脑广告
手机广告位-内容正文底部
上一篇:moltrade
下一篇:Moltbot Best Practices


微信扫一扫,打赏作者吧~