Google Calendar
2026-03-26
新闻来源:网淘吧
围观:56
电脑广告
手机广告
Google Calendar
通过托管的 OAuth 认证访问 Google Calendar API。创建和管理事件、列出日历以及检查可用性。
快速开始
# 列出即将发生的事件
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/google-calendar/calendar/v3/calendars/primary/events?maxResults=10&orderBy=startTime&singleEvents=true')
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-calendar/{native-api-path}
替换{native-api-path}为实际的 Google Calendar API 端点路径。网关将请求代理到www.googleapis.com并自动注入您的 OAuth 令牌。
认证
所有请求都需要在 Authorization 头部中包含 Maton API 密钥:
Authorization: Bearer $MATON_API_KEY
环境变量:将您的 API 密钥设置为MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
获取您的API密钥
- 登录或创建一个账户,访问maton.ai
- 前往maton.ai/settings
- 复制您的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-calendar&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-calendar'}).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-calendar",
"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 Calendar 连接,请使用Maton-Connection标头来指定要使用哪一个:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/google-calendar/calendar/v3/calendars/primary/events')
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-calendar/calendar/v3/users/me/calendarList
获取日历
GET /google-calendar/calendar/v3/calendars/{calendarId}
使用主要针对用户的主要日历。
列出事件
GET /google-calendar/calendar/v3/calendars/primary/events?maxResults=10&orderBy=startTime&singleEvents=true
带时间范围:
GET /google-calendar/calendar/v3/calendars/primary/events?timeMin=2024-01-01T00:00:00Z&timeMax=2024-12-31T23:59:59Z&singleEvents=true&orderBy=startTime
获取事件
GET /google-calendar/calendar/v3/calendars/primary/events/{eventId}
创建事件
POST /google-calendar/calendar/v3/calendars/primary/events
Content-Type: application/json
{
"summary": "团队会议",
"description": "每周同步",
"start": {
"dateTime": "2024-01-15T10:00:00",
"timeZone": "America/Los_Angeles"
},
"end": {
"dateTime": "2024-01-15T11:00:00",
"timeZone": "America/Los_Angeles"
},
"attendees": [
{"email": "attendee@example.com"}
]
}
创建全天事件
POST /google-calendar/calendar/v3/calendars/primary/events
Content-Type: application/json
{
"summary": "全天事件",
"start": {"date": "2024-01-15"},
"end": {"date": "2024-01-16"}
}
更新事件
PUT /google-calendar/calendar/v3/calendars/primary/events/{eventId}
Content-Type: application/json
{
"summary": "更新后的会议标题",
"start": {"dateTime": "2024-01-15T10:00:00Z"},
"end": {"dateTime": "2024-01-15T11:00:00Z"}
}
修补事件(部分更新)
PATCH /google-calendar/calendar/v3/calendars/primary/events/{eventId}
Content-Type: application/json
{
"summary": "仅新标题"
}
删除事件
DELETE /google-calendar/calendar/v3/calendars/primary/events/{eventId}
快速添加事件(自然语言)
POST /google-calendar/calendar/v3/calendars/primary/events/quickAdd?text=Meeting+with+John+tomorrow+at+3pm
空闲/忙碌查询
POST /google-calendar/calendar/v3/freeBusy
Content-Type: application/json
{
"timeMin": "2024-01-15T00:00:00Z",
"timeMax": "2024-01-16T00:00:00Z",
"items": [{"id": "primary"}]
}
代码示例
JavaScript
// 列出事件
const response = await fetch(
'https://gateway.maton.ai/google-calendar/calendar/v3/calendars/primary/events?maxResults=10&singleEvents=true',
{
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
}
}
);
// 创建事件
await fetch(
'https://gateway.maton.ai/google-calendar/calendar/v3/calendars/primary/events',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
},
body: JSON.stringify({
summary: '会议',
start: { dateTime: '2024-01-15T10:00:00Z' },
end: { dateTime: '2024-01-15T11:00:00Z' }
})
}
);
Python
import os
import requests
headers = {'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'}
# 列出事件
events = requests.get(
'https://gateway.maton.ai/google-calendar/calendar/v3/calendars/primary/events',
headers=headers,
params={'maxResults': 10, 'singleEvents': 'true'}
).json()
# 创建事件
response = requests.post(
'https://gateway.maton.ai/google-calendar/calendar/v3/calendars/primary/events',
headers=headers,
json={
'summary': '会议',
'start': {'dateTime': '2024-01-15T10:00:00Z'},
'end': {'dateTime': '2024-01-15T11:00:00Z'}
}
)
注意
- 使用
primary作为用户主日历的 calendarId - 时间必须采用 RFC3339 格式(例如,
2024-01-15T10:00:00Z) - 对于重复事件,请使用
singleEvents=true来展开实例 orderBy=startTimerequiressingleEvents=true- 重要提示:使用curl命令时,如果URL包含方括号(
fields[]、sort[]、records[]),请使用curl -g以禁用通配符解析 - 重要提示:将curl输出通过管道传递给
jq或其他命令时,在某些shell环境中,$MATON_API_KEY等环境变量可能无法正确展开。通过管道传递时,您可能会遇到“无效的API密钥”错误。
错误处理
| 状态 | 含义 |
|---|---|
| 400 | 缺少谷歌日历连接 |
| 401 | Maton API密钥无效或缺失 |
| 429 | 请求频率受限(每个账户每秒10次请求) |
| 4xx/5xx | 来自谷歌日历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-calendar开头。例如:
- 正确:
https://gateway.maton.ai/google-calendar/calendar/v3/calendars/primary/events - 错误:
https://gateway.maton.ai/calendar/v3/calendars/primary/events
资源
文章底部电脑广告
手机广告位-内容正文底部
上一篇:AI Persona OS
下一篇:LinkedIn


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