协作办公
首次从零配置 Google Workspace CLI…
当你要首次搭建 gws CLI、配置 Google Workspace API/OAuth 权限、认证账号,并为 Claude Code 安装 90+ gws 技能或排查 gws 认证问题时使用。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
首次从零配置 Google Worksp特定
解决思路
- 预检已有状态:运行 `which gws && gws --version`,检查 `ls ~/.config/gws/client_secret.json`,运行 `gws auth status`;若 `gws auth status` 显示认证成功且有 scopes,跳到第 6 步安装技能。
- 安装 CLI:运行 `npm install -g @googleworkspace/cli`,然后运行 `gws --version` 确认。
- 创建或选择 GCP 项目:打开 `https://console.cloud.google.com/projectcreate`,创建新项目或使用已有项目;询问用户偏好。
- 启用 Google Workspace APIs:打开 `https://console.cloud.google.com/apis/library?project=PROJECT_ID`,搜索并启用 Gmail API、Google Drive API、Google Calendar API、Google Sheets API、Google Docs API、Google Chat API、Tasks API、People API、Google Slides API、Google Forms API、Admin SDK API(可选,用于 Workspace 管理功能)。
- 配置 Google Chat App(Chat API 必需):打开 `https://console.cloud.google.com/apis/api/chat.googleapis.com/hangouts-chat?project=PROJECT_ID`,进入 Configuration 标签,填写应用详情(名称、头像、描述,CLI 使用可不重要),在 Functionality 下勾选 Spaces and group conversations,在 Connection settings 下选择 Apps Script 或 HTTP endpoint 任意一项,保存;否则 Chat API 调用会报错;通过 `gws` 发送的消息仍以已认证用户身份出现。
- 配置 OAuth consent screen:打开 `https://console.cloud.google.com/apis/credentials/consent?project=PROJECT_ID`,User Type 选 External,App name 填 `gws CLI`,填写用户支持邮箱和开发者联系邮箱,scopes 留空(gws 登录时请求),将 Google 账号添加为 test user,保存并继续所有页面。
- 创建 OAuth client ID:打开 `https://console.cloud.google.com/apis/credentials?project=PROJECT_ID`,点击 Create Credentials → OAuth client ID,Application type 选 Desktop app,Name 填 `gws CLI`,点击 Create,复制 JSON 或下载 `client_secret_*.json`。
- 保存凭据:请用户粘贴 `client_secret.json` 内容或提供下载文件路径;运行 `mkdir -p ~/.config/gws`;将 JSON 写入 `~/.config/gws/client_secret.json`;格式为 `installed` 对象,包含 `client_id`、`project_id`、`auth_uri`、`token_uri`、`client_secret`、`redirect_uris`(值为 `http://localhost`)。
- 选择 scopes:询问用户访问级别;Full access 推荐命令 `gws auth login --full`;Core services 命令 `gws auth login -s gmail,drive,calendar,sheets,docs,chat,tasks`;Minimal 命令 `gws auth login -s gmail,calendar`;推荐 power user 用 full access;OAuth consent screen 会展示请求的 scopes 供审查。
- 处理 Testing 状态 scope 限制:如果 GCP app 在 Testing 状态,scope 选择限制约 25 个;用 `-s service1,service2` 请求目标 scopes,或将 app 发布到 Production 以获取更广 scope。
- 认证并处理长 OAuth URL:运行 `gws auth login --full 2>&1 | tee /tmp/gws-auth-output.txt`(或 `gws auth login -s gmail,drive,calendar,sheets,docs,chat,tasks 2>&1 | tee /tmp/gws-auth-output.txt`);可后台运行,用户浏览器批准后完成。
- 提取并打开 OAuth URL:运行 `grep -o 'https://accounts.google.com[^ ]*' /tmp/gws-auth-output.txt > /tmp/gws-auth-url.txt`;运行 `cat /tmp/gws-auth-url.txt | xargs open`;如果 `open` 失败,告诉用户打开 `/tmp/gws-auth-url.txt` 并复制 URL。
- 等待浏览器批准并验证认证:用户批准后 gws 将加密凭据存到 `~/.config/gws/credentials.enc`;运行 `gws auth status`,应显示 `status` 为 `success`,并显示认证账号和授予的 scopes。
- 安装 Agent Skills:运行 `npx skills add googleworkspace/cli -g --agent claude-code --all` 全局安装 90+ gws agent skills。
- 验证技能安装:运行 `ls ~/.claude/skills/gws-* | wc -l`,应显示 30+ 个 gws 技能目录。
- 为其他机器保存凭据:运行 `gws auth export` 输出解密凭据(含 refresh token);`client_secret.json` 是可移植部分,同一 OAuth client 可在任何机器使用,每台机器用 `gws auth login` 生成新用户 token;将 `client_secret.json` 内容保存到安全位置(密码管理器、加密笔记),供其他机器上的 `gws-install` 技能使用。
- 验证全部可用:运行 `gws auth status`、`gws calendar +agenda --today`、`gws gmail +triage`;如果任何命令因认证错误失败,重新运行 `gws auth login` 并带上所需 scopes。
- 长期使用时转 Production:GCP OAuth app 初始为 Testing 状态,有 7 天 token 过期和约 25 个 scope 限制;在 OAuth consent screen 设置中将 app 推到 Production;Production app 无 token 过期限制;个人/内部使用 Google 不要求验证。
- 按服务 flag 选择 scopes:`gmail` 启用收发/管理邮件、标签、过滤器;`drive` 启用文件、文件夹、共享盘;`calendar` 启用事件、日历、空闲/忙碌;`sheets` 启用读写电子表格;`docs` 启用读写文档;`chat` 启用空间、消息;`tasks` 启用任务列表和任务;`slides` 启用演示文稿;`forms` 启用表单和回复;`people` 启用联系人和个人资料;`admin` 启用 Workspace 管理(目录、设备、组)。
- 使用环境变量替代 `client_secret.json`:运行 `export GOOGLE_WORKSPACE_CLI_CLIENT_ID="your-client-id"`、`export GOOGLE_WORKSPACE_CLI_CLIENT_SECRET="your-client-secret"`,然后 `gws auth login`。
- 使用 `~/.config/gws/` 管理配置:`client_secret.json` 是 OAuth client 凭据(可移植),`credentials.enc` 是加密用户 token(每机器),`token_cache.json` 是 token 刷新缓存,`cache/` 是 API discovery schema 缓存。
适用边界 · 注意事项
- 不适用于非 Claude Code 环境,因为 compatibility 为 claude-code-only。
- 没有 Google 账号或无法访问 Google Cloud Console 时不适用。
- 不愿创建和管理 GCP OAuth Desktop App 凭据、或不接受 Google OAuth 授权时不适用。