first build nexus
This commit is contained in:
212
AI/openclaw/GOG-CLI-安装配置指南.md
Normal file
212
AI/openclaw/GOG-CLI-安装配置指南.md
Normal file
@@ -0,0 +1,212 @@
|
||||
#gog #gog-cli #macos
|
||||
|
||||
本文档记录在 macOS 系统上安装和配置 gog CLI 的完整步骤,以便通过命令行管理 Google Workspace(Gmail、Google Calendar、Google Drive、Google Contacts、Google Docs、Google Sheets)。
|
||||
|
||||
## 目录
|
||||
|
||||
- [前置条件](#前置条件)
|
||||
- [安装步骤](#安装步骤)
|
||||
- [配置 OAuth 凭证](#配置-oauth-凭证)
|
||||
- [解除 Google 安全限制](#解除-google-安全限制)
|
||||
- [验证配置](#验证配置)
|
||||
- [常用命令](#常用命令)
|
||||
- [故障排除](#故障排除)
|
||||
|
||||
---
|
||||
|
||||
## 前置条件
|
||||
|
||||
- macOS 系统
|
||||
- Homebrew 已安装
|
||||
- Google 账号
|
||||
|
||||
---
|
||||
|
||||
## 安装步骤
|
||||
|
||||
### 1. 安装 gog CLI
|
||||
|
||||
使用 Homebrew 安装 gog CLI:
|
||||
|
||||
```bash
|
||||
brew install steipete/tap/gogcli
|
||||
```
|
||||
|
||||
验证安装:
|
||||
|
||||
```bash
|
||||
which gog
|
||||
# 输出: /opt/homebrew/bin/gog
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 配置 OAuth 凭证
|
||||
|
||||
### 1. 在 Google Cloud Console 创建 OAuth 凭证
|
||||
|
||||
1. 打开 [Google Cloud Console - Credentials](https://console.cloud.google.com/apis/credentials)
|
||||
2. 点击 **「创建凭证」** → 选择 **「OAuth 客户端 ID」**
|
||||
3. 应用类型选择 **「桌面应用」**
|
||||
4. 命名(例如:`gogcli`)
|
||||
5. 点击 **「创建」**
|
||||
6. 点击 **「下载 JSON」**,得到 `credentials.json` 文件
|
||||
|
||||
### 2. 移动凭证文件到 gogcli 配置目录
|
||||
|
||||
创建 gogcli 配置目录(如果不存在):
|
||||
|
||||
```bash
|
||||
mkdir -p "/Users/weishen/Library/Application Support/gogcli"
|
||||
```
|
||||
|
||||
移动下载的凭证文件:
|
||||
|
||||
```bash
|
||||
mv ~/Downloads/credentials.json "/Users/weishen/Library/Application Support/gogcli/credentials.json"
|
||||
```
|
||||
|
||||
或者使用命令指定凭证路径:
|
||||
|
||||
```bash
|
||||
gog auth credentials /path/to/credentials.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 解除 Google 安全限制
|
||||
|
||||
### 问题描述
|
||||
|
||||
首次授权时,Google 会显示以下错误:
|
||||
|
||||
> 此应用未经 Google 验证
|
||||
> 此应用请求访问您 Google 账号中的敏感信息。在开发者让该应用通过 Google 验证之前,请勿使用该应用。
|
||||
|
||||
### 解决方法:添加测试用户
|
||||
|
||||
1. 打开 [Google Cloud Console - Credentials](https://console.cloud.google.com/apis/credentials)
|
||||
2. 找到你创建的 OAuth 客户端ID,点击进入详情
|
||||
3. 找到 **「测试用户」** 部分
|
||||
4. 点击 **「添加用户」**
|
||||
5. 输入你的 Google 邮箱:`ishenwei@gmail.com`
|
||||
6. 保存
|
||||
|
||||
添加测试用户后,重新运行授权命令即可:
|
||||
|
||||
```bash
|
||||
gog auth add ishenwei@gmail.com --services gmail,calendar,drive,contacts,docs,sheets
|
||||
```
|
||||
|
||||
这会打开浏览器让你登录 Google 账号并授权。
|
||||
|
||||
---
|
||||
|
||||
## 验证配置
|
||||
|
||||
### 1. 查看已授权的账号
|
||||
|
||||
```bash
|
||||
gog auth list
|
||||
```
|
||||
|
||||
### 2. 测试 Gmail
|
||||
|
||||
```bash
|
||||
gog gmail search "newer_than:1d" --max 5
|
||||
```
|
||||
|
||||
### 3. 测试 Calendar
|
||||
|
||||
```bash
|
||||
gog calendar events primary --from 2026-01-01 --to 2026-12-31
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 常用命令
|
||||
|
||||
### Gmail
|
||||
|
||||
| 功能 | 命令 |
|
||||
|------|------|
|
||||
| 搜索邮件 | `gog gmail search 'newer_than:7d' --max 10` |
|
||||
| 发送邮件 | `gog gmail send --to a@b.com --subject "Hi" --body "Hello"` |
|
||||
| 发送邮件(多行) | `gog gmail send --to a@b.com --subject "Hi" --body-file ./message.txt` |
|
||||
| 创建草稿 | `gog gmail drafts create --to a@b.com --subject "Hi" --body-file ./message.txt` |
|
||||
| 发送草稿 | `gog gmail drafts send <draftId>` |
|
||||
|
||||
### Calendar
|
||||
|
||||
| 功能 | 命令 |
|
||||
|------|------|
|
||||
| 查看事件 | `gog calendar events <calendarId> --from <iso> --to <iso>` |
|
||||
| 创建事件 | `gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso>` |
|
||||
| 查看颜色 | `gog calendar colors` |
|
||||
|
||||
### Drive
|
||||
|
||||
| 功能 | 命令 |
|
||||
|------|------|
|
||||
| 搜索文件 | `gog drive search "query" --max 10` |
|
||||
|
||||
### Contacts
|
||||
|
||||
| 功能 | 命令 |
|
||||
|------|------|
|
||||
| 列出联系人 | `gog contacts list --max 20` |
|
||||
|
||||
### Sheets
|
||||
|
||||
| 功能 | 命令 |
|
||||
|------|------|
|
||||
| 获取数据 | `gog sheets get <sheetId> "Tab!A1:D10" --json` |
|
||||
| 更新数据 | `gog sheets update <sheetId> "Tab!A1:B2" --values-json '[["A","B"],["1","2"]]' --input USER_ENTERED` |
|
||||
|
||||
### Docs
|
||||
|
||||
| 功能 | 命令 |
|
||||
|------|------|
|
||||
| 导出文档 | `gog docs export <docId> --format txt --out /tmp/doc.txt` |
|
||||
| 查看内容 | `gog docs cat <docId>` |
|
||||
|
||||
---
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 凭证文件路径错误
|
||||
|
||||
确保凭证文件在以下位置:
|
||||
```
|
||||
/Users/weishen/Library/Application Support/gogcli/credentials.json
|
||||
```
|
||||
|
||||
### 需要重新授权
|
||||
|
||||
删除现有授权并重新授权:
|
||||
|
||||
```bash
|
||||
gog auth remove ishenwei@gmail.com
|
||||
gog auth add ishenwei@gmail.com --services gmail,calendar,drive,contacts,docs,sheets
|
||||
```
|
||||
|
||||
### 设置默认账号
|
||||
|
||||
避免每次重复指定账号:
|
||||
|
||||
```bash
|
||||
export GOG_ACCOUNT=ishenwei@gmail.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 参考链接
|
||||
|
||||
- gog 官网: https://gogcli.sh
|
||||
- gog GitHub: https://github.com/steipete/gogcli
|
||||
- Google Cloud Console: https://console.cloud.google.com/
|
||||
|
||||
---
|
||||
|
||||
*文档创建日期: 2026-03-15*
|
||||
*最后更新: 2026-03-15*
|
||||
Reference in New Issue
Block a user