Google Calendar Skill
Overview
This skill provides a thin wrapper around the Google Calendar REST API. It lets you:
- - list upcoming events (optionally filtered by time range or query)
- add a new event with title, start/end time, description, location, and attendees
- update an existing event by its ID
- delete an event by its ID
The skill is implemented in Python (scripts/google_calendar.py). It expects the following environment variables to be set (you can store them securely with openclaw secret set):
GOOGLE_CLIENT_ID=…
GOOGLE_CLIENT_SECRET=…
GOOGLE_REFRESH_TOKEN=… # obtained after OAuth consent
GOOGLE_CALENDAR_ID=primary # or the ID of a specific calendar
The first time you run the skill you may need to perform an OAuth flow to obtain a refresh token – see the
Setup section below.
Commands
google-calendar list [--from <ISO> --to <ISO> --max <N>]
google-calendar add --title <title> [--start <ISO> --end <ISO>]
[--desc <description> --location <loc> --attendees <email1,email2>]
google-calendar update --event-id <id> [--title <title> ... other fields]
google-calendar delete --event-id <id>
All commands return a JSON payload printed to stdout. Errors are printed to stderr and cause a non‑zero exit code.
Setup
- 1. Create a Google Cloud project and enable the Google Calendar API.
- Create OAuth credentials (type Desktop app). Note the
client_id and client_secret. - Run the helper script to obtain a refresh token:
GOOGLE_CLIENT_ID=… GOOGLE_CLIENT_SECRET=… python3 -m google_calendar.auth
It will open a browser (or print a URL you can open elsewhere) and ask you to grant access. After you approve, copy the
refresh_token it prints.
- 4. Store the credentials securely:
openclaw secret set GOOGLE_CLIENT_ID <value>
openclaw secret set GOOGLE_CLIENT_SECRET <value>
openclaw secret set GOOGLE_REFRESH_TOKEN <value>
openclaw secret set GOOGLE_CALENDAR_ID primary # optional
- 5. Install the required Python packages (once):
CODEBLOCK4
How it works (brief)
The script loads the credentials from the environment, refreshes the access token using the refresh token, builds a
service = build('calendar', 'v3', credentials=creds), and then calls the appropriate API method.
References
- - Google Calendar API reference: https://developers.google.com/calendar/api/v3/reference
- OAuth 2.0 for installed apps: https://developers.google.com/identity/protocols/oauth2/native-app
Note: This skill does not require a GUI; it works entirely via HTTP calls, so it is suitable for headless servers.
技能名称: google-calendar
Google日历技能
概述
本技能是对Google日历REST API的轻量封装。它允许您:
- - 列出即将到来的事件(可选择按时间范围或查询条件过滤)
- 添加新事件,包含标题、开始/结束时间、描述、地点和参与者
- 通过ID更新现有事件
- 通过ID删除事件
该技能使用Python实现(scripts/google_calendar.py)。它需要设置以下环境变量(您可以使用openclaw secret set安全存储):
GOOGLECLIENTID=…
GOOGLECLIENTSECRET=…
GOOGLEREFRESHTOKEN=… # 通过OAuth授权后获取
GOOGLECALENDARID=primary # 或特定日历的ID
首次运行该技能时,您可能需要执行OAuth流程以获取刷新令牌——请参阅下方的设置部分。
命令
google-calendar list [--from --to --max ]
google-calendar add --title <标题> [--start --end ]
[--desc <描述> --location <地点> --attendees <邮箱1,邮箱2>]
google-calendar update --event-id [--title <标题> ... 其他字段]
google-calendar delete --event-id
所有命令均将JSON数据输出到标准输出。错误信息输出到标准错误,并导致非零退出码。
设置
- 1. 创建Google Cloud项目并启用Google日历API。
- 创建OAuth凭据(类型选择桌面应用)。记录clientid和clientsecret。
- 运行辅助脚本获取刷新令牌:
bash
GOOGLE
CLIENTID=… GOOGLE
CLIENTSECRET=… python3 -m google_calendar.auth
该脚本将打开浏览器(或打印一个可在他处打开的URL)并请求您授予访问权限。批准后,复制其打印的refresh_token。
- 4. 安全存储凭据:
bash
openclaw secret set GOOGLE
CLIENTID <值>
openclaw secret set GOOGLE
CLIENTSECRET <值>
openclaw secret set GOOGLE
REFRESHTOKEN <值>
openclaw secret set GOOGLE
CALENDARID primary # 可选
- 5. 安装所需的Python包(一次性操作):
bash
pip install --user google-auth google-auth-oauthlib google-api-python-client
工作原理(简述)
脚本从环境加载凭据,使用刷新令牌更新访问令牌,构建service = build(calendar, v3, credentials=creds),然后调用相应的API方法。
参考
- - Google日历API参考:https://developers.google.com/calendar/api/v3/reference
- 已安装应用的OAuth 2.0:https://developers.google.com/identity/protocols/oauth2/native-app
注意: 本技能无需图形界面;它完全通过HTTP调用工作,因此适用于无头服务器。