返回顶部
g

google-workspace-byok谷歌工作区BYOK

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
794
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

google-workspace-byok

Google Workspace BYoK(自带密钥)

使用您自己的GCP项目OAuth2凭据直接访问Google日历和Gmail API。支持多个Google账号。

前提条件

  • - Node.js(v18+)
  • 已启用日历和Gmail API的Google Cloud项目
  • 来自GCP项目的OAuth2 桌面应用凭据

设置

步骤1:安装依赖

bash
cd {baseDir}/scripts && npm install

这将安装googleapis(Google API客户端)和mupdf(用于邮件附件的PDF文本提取)。

步骤2:创建Google Cloud项目

  1. 1. 前往Google Cloud控制台并创建一个新项目(或使用现有项目)
  2. 启用Google Calendar APIGmail API
- 前往API和服务 → 库 - 搜索Google Calendar API → 点击启用 - 搜索Gmail API → 点击启用

步骤3:配置OAuth同意屏幕

  1. 1. 前往Google Auth平台 → 受众群体直接链接
  2. 如果提示,配置同意屏幕:
- 应用名称:任意名称(例如OpenClaw) - 用户支持邮箱:您的邮箱 - 范围:跳过(认证脚本在运行时请求范围)
  1. 3. 如果您的应用处于测试发布状态(默认),请将您要授权的每个Google账号添加为测试用户
- 在测试用户下,点击添加用户 - 输入您将连接的每个账号的邮箱地址 - 保存

⚠️ 重要提示: 处于测试状态的应用具有7天令牌有效期。要获取长期令牌,请在受众群体设置中将您的应用发布为正式版。对于个人Gmail账号(外部用户类型),您可以跳过Google的验证审核——在同意过程中您只会看到未验证应用警告。这对个人使用没有问题。

步骤4:创建OAuth凭据

  1. 1. 前往Google Auth平台 → 客户端直接链接
  2. 点击创建客户端 → 选择桌面应用作为应用类型
  3. 任意命名(例如OpenClaw)
  4. 点击创建下载凭据JSON
  5. 运行设置脚本:

bash
node {baseDir}/scripts/setup.js --credentials /path/to/downloaded-credentials.json

这将把您的凭据复制到~/.openclaw/google-workspace-byok/credentials.json。

步骤5:授权Google账号

对于您要连接的每个Google账号:

bash
node {baseDir}/scripts/auth.js --account <标签>

<标签>是您将用来引用此账号的友好名称(例如personal、work、household)。

认证流程:

  1. 1. 脚本打印一个授权URL
  2. 在浏览器中打开该URL并使用Google账号登录
  3. 授予请求的权限
  4. 您将被重定向到http://localhost/...——页面不会加载,这是正常现象
  5. 从浏览器地址栏复制完整URL并粘贴回脚本
  6. 脚本将代码交换为令牌并保存

请求的范围(默认——读/写):

  • - calendar — Google日历的完全读/写访问权限
  • gmail.readonly — Gmail的只读访问权限

传递--readonly以请求只读日历访问权限。

令牌存储在~/.openclaw/google-workspace-byok/tokens/<标签>.json中。

使用方法

所有脚本都在{baseDir}/scripts/中。使用node运行它们。

日历

bash

列出所有日历


node {baseDir}/scripts/calendar.js --account <标签> --action list-calendars

列出即将到来的事件(默认:未来7天,主日历)

node {baseDir}/scripts/calendar.js --account <标签> --action events

带选项列出事件

node {baseDir}/scripts/calendar.js --account <标签> --action events --calendar --days <数字> --max <数字>

获取特定事件

node {baseDir}/scripts/calendar.js --account <标签> --action get-event --calendar --event-id

检查空闲/忙碌

node {baseDir}/scripts/calendar.js --account <标签> --action freebusy --days <数字>

Gmail

bash

列出最近的邮件(默认:10封)


node {baseDir}/scripts/gmail.js --account <标签> --action list

搜索邮件

node {baseDir}/scripts/gmail.js --account <标签> --action list --query from:someone@example.com --max 20

读取特定邮件(包含带ID的附件元数据)

node {baseDir}/scripts/gmail.js --account <标签> --action read --message-id

下载邮件中的所有附件

node {baseDir}/scripts/gmail.js --account <标签> --action attachment --message-id --out-dir /tmp/attachments

下载特定附件

node {baseDir}/scripts/gmail.js --account <标签> --action attachment --message-id --attachment-id --out-dir /tmp

列出标签

node {baseDir}/scripts/gmail.js --account <标签> --action labels

Gmail搜索使用与Gmail网页搜索框相同的查询语法(例如is:unread、from:、newer_than:1d、has:attachment)。

读取PDF附件

该技能包含mupdf用于从PDF附件中提取文本——适用于新闻简报、发票、学校信件等。它能够很好地处理多语言文本(日语、中文等)。

bash

1. 下载附件


mkdir -p /tmp/attachments
node {baseDir}/scripts/gmail.js --account <标签> --action attachment --message-id --out-dir /tmp/attachments

2. 从PDF中提取文本

node --input-type=module -e import * as mupdf from {baseDir}/scripts/node_modules/mupdf/dist/mupdf.js; import fs from fs; const data = fs.readFileSync(/tmp/attachments/filename.pdf); const doc = mupdf.Document.openDocument(data, application/pdf); for (let i = 0; i < doc.countPages(); i++) { const page = doc.loadPage(i); console.log(page.toStructuredText(preserve-whitespace).asText()); }

注意: mupdf是一个ESM模块——使用node --input-type=module配合import语法,而不是require()。

账号管理

bash

列出已配置的账号


node {baseDir}/scripts/accounts.js --action list

检查令牌状态

node {baseDir}/scripts/accounts.js --action status --account <标签>

文件结构

~/.openclaw/google-workspace-byok/
├── credentials.json # 您的GCP OAuth凭据
└── tokens/
├── personal.json # personal账号的令牌
└── work.json # work账号的令牌

故障排除

Error 403: access_denied — 尚未完成Google验证过程

您的应用处于测试模式,且该Google账号未列为测试用户。解决方法:前往Google Auth平台 → 受众群体 → 测试用户 → 添加该邮箱。

Error: invalid_grant

刷新令牌已过期或被撤销。重新运行node {baseDir}/scripts/auth.js --account <标签>以重新授权。

令牌在7天后过期

处于测试发布状态的应用颁发的令牌在7天后过期。将您的应用发布为正式版以获取长期令牌。对于个人Gmail(外部用户类型),您可以跳过验证,只需接受未验证应用警告。

Error: redirecturimismatch

您的credentials.json不包含http://localhost作为重定向URI。在GCP控制台中编辑您的OAuth客户端 → 授权重定向URI → 添加http://localhost。

npm install失败或mupdf无法安装

mupdf在某些平台上需要C++构建工具链。如果安装失败,您仍然可以使用所有其他功能——PDF文本提取是唯一需要它的功能。尝试:npm install --ignore-scripts以跳过原生编译,然后根据需要单独安装mupdf。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 google-workspace-byok-1776420049 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 google-workspace-byok-1776420049 技能

通过命令行安装

skillhub install google-workspace-byok-1776420049

下载

⬇ 下载 google-workspace-byok v1.0.0(免费)

文件大小: 24.49 KB | 发布时间: 2026-4-17 19:43

v1.0.0 最新 2026-4-17 19:43
- Initial release of google-workspace-byok.
- Enables Google Calendar and Gmail integration using your own Google Cloud project credentials (Bring Your Own Key).
- Supports direct OAuth2 authentication, management of multiple Google accounts, and both read and write access.
- Features include: listing/reading emails, Gmail search, downloading attachments (with text extraction from PDFs), listing/getting calendar events, and checking free/busy status.
- Provides setup instructions, account management, and detailed troubleshooting in SKILL.md.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部