← 返回 Skills 市场
han880520

飞书云盘助手

作者 han880520 · GitHub ↗ · v1.1.5 · MIT-0
cross-platform ✓ 安全检测通过
168
总下载
0
收藏
0
当前安装
15
版本数
在 OpenClaw 中安装
/install feishu-cloud-drive
功能描述
基于飞书官方 API 的云盘管理技能,支持文件列表查询、上传、下载、文件夹创建、权限管理、文件搜索、统计信息、快捷方式、复制移动等完整功能。参考 feishu-drive 技能开发,修复了原技能中的 API 调用错误,并新增了自动化权限管理功能。
使用说明 (SKILL.md)

🎯 项目起源

本技能参考了社区中的 feishu-drive 技能,但在实现过程中发现原技能存在以下问题:

  1. API 接口错误:使用了错误的 API 路径(如 GET /open-apis/drive/v1/files/:token/children 应改为 drive/explorer/v2 版本)
  2. 文档与实际不符:SKILL.md 中描述的 API 与飞书官方文档不一致
  3. 权限管理缺失:创建的文件夹默认只有机器人可见,未处理权限问题

因此基于飞书官方文档重新开发了此技能,修复了所有已知问题,并新增了权限管理功能。


飞书云盘管理 (官方API版本)

你是飞书云盘管理专家,负责通过飞书官方 API 实现文件列表查询、上传、下载和文件夹管理。

使用方式

1. 配置环境变量

设置环境变量:

export FEISHU_APP_ID="your_app_id"
export FEISHU_APP_SECRET="your_app_secret"
export FEISHU_ROOT_FOLDER_TOKEN="your_folder_token"  # 可选:指定默认根目录

2. 设置根目录(推荐)

在使用技能之前,先指定一个根目录,后续所有操作都以此目录为基准:

from feishu_drive_client import create_client, FeishuDriveClient
import os

# 方式1:使用便捷函数(推荐)
# 自动从环境变量 FEISHU_APP_ID, FEISHU_APP_SECRET, FEISHU_ROOT_FOLDER_TOKEN 读取
client = create_client()

# 方式2:手动创建客户端,从环境变量读取
client = FeishuDriveClient(
    app_id=os.getenv("FEISHU_APP_ID"),
    app_secret=os.getenv("FEISHU_APP_SECRET"),
    root_folder_token=os.getenv("FEISHU_ROOT_FOLDER_TOKEN")  # 可选
)

# 方式3:手动指定所有参数
client = FeishuDriveClient(
    app_id="your_app_id",
    app_secret="your_app_secret",
    root_folder_token="your_folder_token"  # 可选
)

# 方式4:后续动态设置根目录
client = FeishuDriveClient(app_id, app_secret)
client.set_root_folder("your_folder_token")

3. 使用示例

设置根目录后,所有操作默认在根目录下进行:

# 在根目录下创建子文件夹(无需传入 folder_token)
result = client.create_folder("新文件夹")

# 在根目录下上传文件
result = client.upload_file("/path/to/file.jpg")

# 列出根目录内容
result = client.list_folder()

# 如需操作其他目录,可临时指定 folder_token
result = client.create_folder("其他位置的文件夹", parent_folder_token="其他token")

优先级规则传入的 folder_token > 设置的 root_folder_token > 空字符串(根目录)


API 基础信息

项目
Base URL https://open.feishu.cn/open-apis/drive/v1
认证方式 Authorization: Bearer {tenant_access_token}
Content-Type application/json (文件上传用 multipart/form-data)

核心功能

1. 获取根文件夹 Token

接口说明: 获取用户"我的空间"根文件夹的元数据

GET /open-apis/drive/explorer/v2/root_folder/meta

响应示例:

{
  "code": 0,
  "data": {
    "token": "nodcnXXXXXX",
    "id": "7110173013420512356",
    "user_id": "7103496998321312356"
  },
  "msg": "success"
}

注意事项:

  • 需要权限: drive:drivedrive:drive.metadata:readonly
  • 返回的 token 可用于后续的文件夹操作

2. 创建文件夹

接口说明: 在指定父文件夹下创建新文件夹

POST /open-apis/drive/v1/files/create_folder

请求参数:

{
  "name": "文件夹名称",
  "folder_token": "父文件夹token"
}

响应示例:

{
  "code": 0,
  "data": {
    "token": "fldcnXXXXXX",
    "url": "https://xxx.feishu.cn/drive/folder/fldcnXXXXXX",
    "name": "文件夹名称"
  }
}

注意事项:

  • folder_token 为父文件夹 token,可以通过 URL 获取或通过 API 查询
  • 创建的文件夹默认只有机器人可见,如需用户可见需要设置权限

3. 获取文件夹内容

接口说明: 获取指定文件夹下的文件和子文件夹列表

推荐方法 (Explorer v2):

GET /open-apis/drive/explorer/v2/folder/:folder_token/children

响应示例:

{
  "code": 0,
  "data": {
    "children": {
      "file_token1": {
        "token": "file_token1",
        "name": "文件名",
        "type": "file"
      },
      "folder_token1": {
        "token": "folder_token1",
        "name": "文件夹名",
        "type": "folder"
      }
    },
    "parentToken": "folder_token"
  },
  "msg": "success"
}

注意事项:

  • typefolder 表示文件夹,为 file 表示文件
  • v2 版本的 children 是字典格式,不是数组

4. 上传文件

接口说明: 上传文件到指定文件夹

POST /open-apis/drive/v1/files/upload_all
Content-Type: multipart/form-data

请求参数:

参数 类型 必填 说明
file binary 文件二进制内容
file_name string 文件名
parent_type string 父节点类型,explorer = 云空间
parent_node string 父节点 token(文件夹 token)
size number 文件大小(字节)

响应示例:

{
  "code": 0,
  "data": {
    "file_token": "file_token"
  }
}

注意事项:

  • parent_type 使用 explorer 表示云空间文件夹
  • size 参数必填,建议在上传前计算文件大小
  • 大文件(超过 10MB)建议使用分片上传接口

5. 下载文件

接口说明: 根据文件 token 下载文件

GET /open-apis/drive/v1/files/:file_token/download

请求参数:

参数 类型 必填 说明
file_token string 文件 token

响应:

  • 返回文件二进制流
  • Content-Type 根据文件类型自动设置

注意事项:

  • 需要在请求头中携带 Authorization: Bearer {tenant_access_token}
  • 下载的是二进制流,需要正确处理响应体

6. 获取用户 Open ID

接口说明: 通过邮箱或手机号获取用户的 open_id

POST /open-apis/contact/v3/users/batch_get_id

请求参数:

{
  "emails": ["[email protected]"],
  "mobiles": ["13800138000"],
  "include_resigned": false
}

响应示例:

{
  "code": 0,
  "data": {
    "user_list": [
      {
        "user_id": "ou_xxxxxxxxx",
        "email": "[email protected]",
        "status": {
          "is_activated": true,
          "is_resigned": false
        }
      }
    ]
  }
}

注意事项:

  • 支持批量查询,最多 50 个邮箱或手机号
  • 需要 contact:user.id:readonly 权限
  • 返回的 user_id 就是 open_id

7. 添加文件夹权限

接口说明: 为文件夹添加用户权限

POST /open-apis/drive/v1/permissions/:token/members?type=folder

请求参数:

{
  "member_type": "openid",
  "member_id": "ou_xxxxxxxxx",
  "perm": "full_access",
  "perm_type": "container",
  "type": "user"
}

权限类型:

perm 说明
view 可阅读
edit 可编辑
full_access 可管理(完全访问)

注意事项:


8. 获取文件元数据

接口说明: 获取文件的详细信息

GET /open-apis/drive/v1/files/:file_token

请求参数:

参数 类型 必填 说明
file_token string 文件或文件夹 token

响应示例:

{
  "code": 0,
  "data": {
    "token": "token",
    "name": "名称",
    "type": "file/folder",
    "size": 1024,
    "created_time": 1234567890,
    "owner": {
      "open_id": "xxx"
    }
  }
}

9. 删除文件夹

接口说明: 删除指定文件夹(删除后进入回收站)

DELETE /open-apis/drive/v1/files/:folder_token?type=folder

请求参数:

参数 类型 必填 说明
folder_token string 文件夹 token
type string 固定值 folder

响应示例:

{
  "code": 0,
  "msg": "success"
}

注意事项:

  • 删除后文件夹会进入回收站,可以在回收站中恢复
  • 需要具有文件夹的编辑权限才能删除
  • 重要: 执行删除操作前必须向用户确认,避免误删

Python 示例:

# 删除文件夹(带确认提示)
def delete_folder_with_confirm(client, folder_token, folder_name, confirmed=False):
    # 1. 显示文件夹信息
    print(f"即将删除文件夹: {folder_name}")
    print(f"Token: {folder_token}")
    
    # 2. 请求用户确认(在自主运行环境中,通过参数传递确认状态)
    if not confirmed:
        print("请设置 confirmed=True 确认删除")
        return
    
    # 3. 执行删除
    result = client.delete_folder(folder_token)
    if result.get("code") == 0:
        print("删除成功!文件夹已进入回收站")
    else:
        print(f"删除失败: {result.get('msg')}")

# 使用示例 - 必须显式确认
delete_folder_with_confirm(client, "folder_token", "测试文件夹", confirmed=True)

10. 删除文件

接口说明: 删除指定文件(删除后进入回收站)

DELETE /open-apis/drive/v1/files/:file_token?type=file

请求参数:

参数 类型 必填 说明
file_token string 文件 token
type string 固定值 file

注意事项:

  • 删除后文件会进入回收站,可以在回收站中恢复
  • 需要具有文件的编辑权限才能删除
  • 重要: 执行删除操作前必须向用户确认

11. 移动文件或文件夹

接口说明: 将文件或文件夹移动到指定文件夹

POST /open-apis/drive/v1/files/:file_token/move

请求参数:

{
  "type": "file",
  "destination_folder_token": "目标文件夹token"
}

类型说明:

type 值 说明
file 普通文件
folder 文件夹
doc 文档
sheet 电子表格
bitable 多维表格
docx 新版文档

12. 复制文件

接口说明: 复制文件到指定文件夹(异步操作)

POST /open-apis/drive/v1/files/:file_token/copy

请求参数:

{
  "type": "file",
  "destination_folder_token": "目标文件夹token",
  "name": "复制后的新名称(可选)"
}

响应示例:

{
  "code": 0,
  "data": {
    "ticket": "task_ticket_xxx"
  },
  "msg": "success"
}

注意事项:

  • 复制是异步操作,返回 ticket 用于查询任务状态
  • 使用 check_task_status(ticket) 查询复制进度

13. 批量获取文件元数据

接口说明: 批量获取多个文件的元数据信息

POST /open-apis/drive/v1/metas/batch_query

请求参数:

{
  "file_tokens": ["token1", "token2", "token3"]
}

限制: 最多 100 个文件 token


14. 获取文件统计信息

接口说明: 获取文件的阅读、点赞、评论等统计信息

POST /open-apis/drive/v1/files/:file_token/statistics

响应示例:

{
  "code": 0,
  "data": {
    "uv": 100,
    "pv": 200,
    "like_count": 10,
    "comment_count": 5
  }
}

15. 获取文件访问记录

接口说明: 获取谁访问了该文件的记录

POST /open-apis/drive/v1/files/:file_token/view_records

请求参数:

{
  "page_size": 50,
  "page_token": "可选的分页token"
}

16. 创建文件快捷方式

接口说明: 在指定文件夹创建文件的快捷方式

POST /open-apis/drive/v1/files/create_shortcut

请求参数:

{
  "file_token": "源文件token",
  "folder_token": "目标文件夹token",
  "type": "file"
}

17. 搜索文件

接口说明: 在云空间中搜索文件

POST /open-apis/suite/docs-api/search/object

请求参数:

{
  "search_key": "title",
  "search_value": "搜索关键词",
  "page_size": 50
}

search_key 说明:

说明
title 按标题搜索
content 按内容搜索

注意事项:

  • 此接口需要 user_access_token,不支持 tenant_access_token

18. 查询异步任务状态

接口说明: 查询复制、移动等异步操作的任务状态

GET /open-apis/drive/v1/files/task_check?ticket=xxx

请求参数:

参数 类型 必填 说明
ticket string 异步任务 ticket

响应示例:

{
  "code": 0,
  "data": {
    "status": "success",
    "file_token": "新文件token"
  }
}

status 说明:

说明
pending 等待中
processing 处理中
success 成功
failed 失败

错误处理

错误码 含义 解决方案
0 成功
99991663 token 过期 重新获取 tenant_access_token
1061002 无权限 检查应用权限和文件夹授权
1061001 文件/文件夹不存在 检查 token 是否正确
1061045 文件大小超限 使用分片上传或减小文件大小
404 文件不存在 常见原因:使用了字典 key 而非 item['token'],参见下方常见错误

⚠️ 常见错误:Token 混淆导致 404

问题描述

在获取文件夹内容后尝试下载文件时,出现 404 错误。

根本原因

混淆了飞书 API 返回数据结构中的两种"token"

{
  "children": {
    "nodcn5OkQG6q8Y4SuSncukJmCtc": {  // ← 错误:这是字典的 key,不是下载用 token
      "token": "KdLTbke3BoN85RxQg5qcswFYnah",  // ← 正确:这才是下载用的 token
      "name": "Screenshot_20260323-115306.png",
      "type": "file"
    }
  }
}

错误写法 ❌

result = client.list_folder(folder_token)
children = result["data"]["children"]
for token, item in children.items():  # ← token 实际是 dict_key (nodcn...)
    file_token = token  # ← 错误!这会导致 404
    client.download_file(file_token, "/path/to/file")

正确写法 ✅

result = client.list_folder(folder_token)
children = result["data"]["children"]
for dict_key, item in children.items():  # dict_key 是 nodcn...
    file_token = item["token"]  # ← 正确!从 item 中获取 token
    client.download_file(file_token, "/path/to/file")

# 或者直接使用 list_all() 方法,它已经处理了这个问题
files = client.list_all(folder_token)
for file in files:
    client.download_file(file["token"], f"/path/to/{file['name']}")

记住这个规则

位置 用途
字典 key nodcn5OkQG6q8Y4SuSncukJmCtc 仅用于迭代,通常不使用
item['token'] KdLTbke3BoN85RxQg5qcswFYnah 下载、删除、复制、移动等所有操作

使用建议

权限配置

确保应用已获取以下权限:

  • drive:file:read - 读取文件
  • drive:file:write - 写入文件
  • drive:folder:read - 读取文件夹
  • drive:folder:write - 创建文件夹
  • contact:user.id:readonly - 获取用户 ID(用于权限管理)

最佳实践

  1. 最小权限原则: 为飞书应用仅授予必需的权限,避免过度授权
  2. 测试应用: 建议创建专门的测试应用,使用受限权限进行开发测试
  3. 权限管理: 通过 API 创建的文件默认只有机器人可见,需要注意权限设置
  4. 冒烟测试: 执行任何操作前,先用 get_file_info 测试 token 是否可用
  5. 分页处理: 文件列表可能很多,务必处理分页逻辑
  6. 错误重试: 对于网络错误和临时错误,建议实现重试机制

安全注意事项

  1. 不要在前端代码中暴露 tenant_access_token
  2. 不要分享生产环境的 FEISHU_APP_SECRET
  3. 不要将凭证提交到代码仓库
  4. 定期轮换访问令牌
  5. 限制文件上传大小,避免滥用
  6. 验证文件类型,防止上传恶意文件
安全使用建议
This skill appears to do what it says: a Feishu Drive client implemented in Python. Before installing or using it, you should: 1) review feishu_drive_client.py yourself (especially permission-related methods) and test in a non-production environment; 2) provide only the minimum Feishu app permissions required and use a dedicated test app if possible; 3) manage FEISHU_APP_SECRET securely (do not embed in code or repos) and rotate it if exposed; 4) be aware SKILL.md references an optional FEISHU_ROOT_FOLDER_TOKEN (not declared as required) and there are small field-name mismatches (user_id/open_id) you may want to validate against the Feishu API in your tenant.
能力评估
Purpose & Capability
Name/description, required binaries (python3/pip3), required env vars (FEISHU_APP_ID, FEISHU_APP_SECRET), and the included Python client all align with a cloud-drive management skill. The code calls only Feishu (open.feishu.cn) endpoints and implements listed features (list/upload/download/folders/permissions).
Instruction Scope
SKILL.md's runtime instructions stay within the Drive management scope and instruct installing 'requests', setting credentials, and using the client. Two minor issues: (1) SKILL.md suggests an optional FEISHU_ROOT_FOLDER_TOKEN environment variable (used by examples) but this optional var is not listed in the declared required envs; (2) there are small doc/code mismatches (e.g., use of 'user_id' vs 'open_id' field names in user lookup/permission flows and some comments about which v2 parameters are supported). These are implementation bugs/ambiguities rather than indicators of extraneous data collection.
Install Mechanism
This is effectively an instruction-only skill with a Python client file; dependency installation is limited to pip installing 'requests' (a common, traceable package). No arbitrary downloads, URL shorteners, or archive extraction are used in the provided artifacts.
Credentials
Only FEISHU_APP_ID and FEISHU_APP_SECRET are required (FEISHU_APP_SECRET is the primary credential). The skill does not request unrelated secrets or multiple external credentials. The optional FEISHU_ROOT_FOLDER_TOKEN is used for convenience in examples but is not required.
Persistence & Privilege
The skill is not always-enabled and does not request elevated platform privileges. It caches tenant_access_token in the client instance (in-memory) which is normal; it does not modify other skill configurations or require persistent system-level changes.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install feishu-cloud-drive
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /feishu-cloud-drive 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.5
feishu-cloud-drive 1.1.5 - No file changes detected in this release. - Behavior and documentation remain unchanged from previous version.
v1.1.4
No file changes detected in this version. - No code or documentation changes found for version 1.1.4. - No user-impacting updates; all functionality remains unchanged.
v1.1.3
- No functional or documentation changes detected in this version. - Version updated without any file modifications.
v1.0.11
- Added primaryEnv field to metadata for improved environment variable management. - Reformatted metadata block for better YAML style consistency. - No functional or API changes; documentation and metadata structure only.
v1.0.10
No functional changes in this release. - Version bumped to 1.0.10. - No modifications detected in files or documentation.
v1.0.9
- Added OpenClaw-compatible metadata block to SKILL.md, specifying required environment variables, binaries, and Python dependencies. - Declared installation requirements for Python 3, pip3, and the 'requests' library. - No changes to code or skill logic; documentation and metadata updates only.
v1.0.8
- Added version field (1.0.8) and updated the feature list in the description to include file search, statistics, shortcuts, copy and move functions. - No functional code or logic changes detected; documentation updates only. - The skill is now labeled as providing a more complete set of cloud drive management features in its summary.
v1.0.7
- No file changes were detected in this release. - Updated documentation: the SKILL.md was improved, providing a more accurate and clear confirmation flow for deletion actions (now requiring explicit confirmation via parameter instead of interactive input). - No functional or code changes.
v1.0.6
- No code or documentation changes detected in this version. - Functionality and instructions remain identical to the previous version.
v1.0.5
No changes detected in this release. - No file changes were made compared to the previous version. - Functionality and documentation remain the same as the prior release.
v1.0.4
feishu-cloud-drive 1.0.4 - 调整用法文档,新增 `create_client()` 快捷函数示例,方便通过环境变量快速创建驱动客户端。 - 用法示例更明确区分不同的客户端初始化方式,包括环境变量自动读取和手动传参方式。 - 在“添加文件夹权限”部分新增权限问题排查说明,并补充官方文档链接,便于用户故障排查。 - 其它文档细节及排版优化,无功能接口变动。
v1.0.3
**Feishu Cloud Drive 1.0.3 Changelog** - Added recommendations and examples for setting a custom root directory (`root_folder_token`) to simplify multi-folder management. - Updated documentation: clarified priority rules when specifying folder tokens in API calls. - Documented new file and folder operations: deletion, movement, copying, and batch file metadata queries. - Added user confirmation advice before file/folder deletion to prevent accidental data loss. - Refined usage instructions and code examples for clearer integration guidance.
v1.0.2
- 新增环境变量要求:需配置 FEISHU_APP_ID 和 FEISHU_APP_SECRET。 - 文档增加“使用方式”和环境变量的配置说明。 - SKILL.md 中新增 required_env_vars 字段,明确依赖项。 - 其余功能及 API 说明无变更。
v1.0.1
Feishu Cloud Drive 1.0.1 - Rebuilt the skill based on official Feishu APIs to ensure accuracy and up-to-date integration. - Fixed API endpoint errors and removed inconsistencies with Feishu's current documentation. - Added automated permission management: users can now be granted access to folders via API. - Supports file/folder listing, upload, download, folder creation, and permission management using official endpoints. - Improved error handling according to official error codes, with clear instructions and best practices included.
v1.0.0
Feishu Cloud Drive 1.0.0 - Initial release based on official Feishu API for cloud drive management. - Fixed incorrect API path issues found in the original feishu-drive skill. - Improved API compatibility and updated documentation to match current Feishu API specs. - Added automatic folder permission management to ensure shared visibility. - Supports file/folder listing, uploading, downloading, folder creation, and permission operations. - Provides clear setup and usage guidance to avoid hidden file issues and ensure bot functionality.
元数据
Slug feishu-cloud-drive
版本 1.1.5
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 15
常见问题

飞书云盘助手 是什么?

基于飞书官方 API 的云盘管理技能,支持文件列表查询、上传、下载、文件夹创建、权限管理、文件搜索、统计信息、快捷方式、复制移动等完整功能。参考 feishu-drive 技能开发,修复了原技能中的 API 调用错误,并新增了自动化权限管理功能。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 168 次。

如何安装 飞书云盘助手?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install feishu-cloud-drive」即可一键安装,无需额外配置。

飞书云盘助手 是免费的吗?

是的,飞书云盘助手 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

飞书云盘助手 支持哪些平台?

飞书云盘助手 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 飞书云盘助手?

由 han880520(@han880520)开发并维护,当前版本 v1.1.5。

💬 留言讨论