|
|
# Google Calendar Skill |
|
|
|
|
|
## 功能说明 |
|
|
|
|
|
为 OpenClaw 提供 Google Calendar 集成,支持: |
|
|
- ✅ 读取日历事件(今日/明日/本周) |
|
|
- ✅ 创建新事件 |
|
|
- ✅ 删除事件 |
|
|
- ✅ 多时区支持 |
|
|
- ✅ 服务账号认证 |
|
|
|
|
|
## 安装 |
|
|
|
|
|
### 1. 安装 Python 依赖 |
|
|
|
|
|
```bash |
|
|
pip install google-auth google-api-python-client |
|
|
``` |
|
|
|
|
|
或在 skill 目录执行: |
|
|
```bash |
|
|
cd /root/.openclaw/workspace/skills/google-calendar |
|
|
pip install -r requirements.txt |
|
|
``` |
|
|
|
|
|
### 2. 配置凭证 |
|
|
|
|
|
凭证文件位置:`/root/.openclaw/credentials/google-calendar-life.json` |
|
|
|
|
|
**获取凭证步骤:** |
|
|
1. 访问 https://console.cloud.google.com/ |
|
|
2. 创建或选择 Google Cloud 项目 |
|
|
3. 启用 Google Calendar API |
|
|
4. 创建服务账号 (Service Account) |
|
|
5. 下载 JSON 密钥文件 |
|
|
6. 将内容保存到凭证文件 |
|
|
7. 共享目标日历给服务账号邮箱(格式:`xxx@xxx.iam.gserviceaccount.com`) |
|
|
|
|
|
### 3. 启用 Skill |
|
|
|
|
|
编辑 `/root/.openclaw-life/openclaw.json`(张大师配置)或 `/root/.openclaw/openclaw.json`(主配置): |
|
|
|
|
|
```json |
|
|
{ |
|
|
"skills": { |
|
|
"entries": { |
|
|
"google-calendar": { |
|
|
"enabled": true |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
``` |
|
|
|
|
|
## 配置 |
|
|
|
|
|
编辑 `config.yaml`: |
|
|
|
|
|
```yaml |
|
|
credentials_path: /root/.openclaw/credentials/google-calendar-life.json |
|
|
timezone: Asia/Shanghai |
|
|
calendar_id: primary # 或具体日历 ID |
|
|
``` |
|
|
|
|
|
## 命令 |
|
|
|
|
|
| 命令 | 说明 | 示例 | |
|
|
|------|------|------| |
|
|
| `/calendar today` | 查看今日日程 | `/calendar today` | |
|
|
| `/calendar tomorrow` | 查看明日日程 | `/calendar tomorrow` | |
|
|
| `/calendar week` | 查看本周日程 | `/calendar week` | |
|
|
| `/calendar status` | 检查连接状态 | `/calendar status` | |
|
|
| `/calendar add` | 添加新事件 | `/calendar add 明天 14:00 开会` | |
|
|
| `/calendar help` | 显示帮助 | `/calendar help` | |
|
|
|
|
|
## 编程接口 |
|
|
|
|
|
```python |
|
|
from google_calendar import GoogleCalendarClient |
|
|
|
|
|
client = GoogleCalendarClient( |
|
|
credentials_path='/root/.openclaw/credentials/google-calendar-life.json', |
|
|
timezone='Asia/Shanghai' |
|
|
) |
|
|
|
|
|
# 获取今日事件 |
|
|
events = client.get_today_events() |
|
|
|
|
|
# 创建事件 |
|
|
from datetime import datetime |
|
|
client.create_event( |
|
|
summary='团队会议', |
|
|
start_time=datetime(2026, 2, 24, 14, 0), |
|
|
description='讨论项目进度' |
|
|
) |
|
|
|
|
|
# 测试连接 |
|
|
status = client.test_connection() |
|
|
print(f"Connected: {status['connected']}") |
|
|
``` |
|
|
|
|
|
## 依赖 |
|
|
|
|
|
- Python 3.8+ |
|
|
- google-auth |
|
|
- google-api-python-client |
|
|
|
|
|
## 故障排查 |
|
|
|
|
|
### 错误:Credentials file not found |
|
|
检查凭证文件路径是否正确,文件是否存在。 |
|
|
|
|
|
### 错误:Failed to initialize Google Calendar service |
|
|
- 确认凭证 JSON 格式正确 |
|
|
- 确认服务账号有 Calendar API 访问权限 |
|
|
- 确认目标日历已共享给服务账号 |
|
|
|
|
|
### 错误:googleapiclient.errors.HttpError: Forbidden |
|
|
服务账号没有访问目标日历的权限。请在 Google Calendar 中共享日历给服务账号邮箱。 |
|
|
|
|
|
## 安全提示 |
|
|
|
|
|
- ⚠️ 凭证文件包含私钥,请妥善保管 |
|
|
- ⚠️ 不要将凭证文件提交到版本控制 |
|
|
- ✅ 使用服务账号而非个人账号进行自动化操作 |
|
|
- ✅ 定期轮换服务账号密钥
|
|
|
|