返回顶部
f

feishu-user 飞书用户操作

Feishu document operations (User Access Token version). Use user access token for authentication. When you need to read, create, write, or append Feishu documents.

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

feishu-user

飞书用户文档操作

使用用户访问令牌认证。通过REST API直接调用飞书开放API。

安装依赖

bash
pip install requests

快速开始

python
from feishu_client import FeishuClient

初始化客户端

client = FeishuClient(useraccesstoken=u-xxx)

获取用户访问令牌

步骤1:从飞书开放平台获取应用凭证

准备以下信息:

  • - APPID - 应用ID(来自飞书开放平台应用设置)
  • APPSECRET - 应用密钥(来自飞书开放平台应用设置)
  • REDIRECT_URI - 授权回调地址

启用以下权限:

  • - docx:document - 文档操作
  • drive:drive.search:readonly - 云盘搜索
  • search:docs:read - 文档搜索

步骤2:生成授权地址

https://accounts.feishu.cn/open-apis/authen/v1/authorize?clientid={YOURAPPID}&responsetype=code&redirecturi={YOURREDIRECT_URI}&scope=docx%3Adocument%20drive%3Adrive.search%3Areadonly%20search%3Adocs%3Aread

步骤3:换取令牌

bash
curl -X POST https://open.feishu.cn/open-apis/authen/v1/access_token \
-H Content-Type: application/json \
-d {
granttype: authorizationcode,
code: {YOUR_CODE},
appid: {YOURAPP_ID},
appsecret: {YOURAPP_SECRET}
}

返回的 accesstoken 即为您的 useraccess_token。



使用示例

python
from feishu_client import FeishuClient

初始化

client = FeishuClient(useraccesstoken=u-xxx)

读取文档

content = client.readdoc(doctoken) print(content)

创建文档

newtoken = client.createdoc(我的新文档) print(f新文档:{new_token})

写入文档

client.writedoc(doctoken, # 标题\n\n内容)

追加内容

client.appenddoc(doctoken, ## 新章节\n\n更多内容)

列出所有块

blocks = client.listblocks(doctoken) for block in blocks: print(block)

获取特定块

block = client.getblock(doctoken, block_id)

更新块

client.updateblock(doctoken, block_id, 新内容)

删除块

client.deleteblock(doctoken, block_id)

便捷函数

不想创建客户端?直接使用函数:

python
from feishuclient import readdocument, createdocument, writedocument, append_document

读取

content = readdocument(doctoken, useraccesstoken=u-xxx)

创建

newtoken = createdocument(标题, useraccesstoken=u-xxx)

写入

writedocument(doctoken, # 内容, useraccesstoken=u-xxx)

追加

appenddocument(doctoken, ## 更多, useraccesstoken=u-xxx)

API参考

FeishuClient

方法描述
readdoc(doctoken)读取文档内容
createdoc(title, foldertoken)
创建新文档 | | writedoc(doctoken, content) | 写入文档(覆盖) | | appenddoc(doctoken, content) | 在末尾追加内容 | | listblocks(doctoken) | 列出所有块 | | getblock(doctoken, block_id) | 获取特定块 | | updateblock(doctoken, block_id, content) | 更新块内容 | | deleteblock(doctoken, block_id) | 删除块 |

注意事项

  1. 1. useraccesstoken 有有效期,需要定期刷新
  2. 授权地址中的 scope 必须在飞书开放平台中启用
  3. 本技能使用用户身份访问个人云文档

相关链接

  • - 飞书开放平台:https://open.feishu.cn
  • 文档API:https://open.feishu.cn/document/ukTMukTMukTM/uADOwUjLwgDMzCM4ATm

令牌自动刷新

使用 feishu_token.py 脚本实现令牌自动刷新。

安装依赖

bash
pip install requests

首次授权

bash

1. 生成授权地址


python feishutoken.py --app-id YOURAPPID --app-secret YOURSECRET --redirect-uri YOURREDIRECTURI --url

用户授权后,将回调到 YOURREDIRECTURI?code=XXX

bash

2. 使用授权码获取令牌


python feishutoken.py --app-id YOURAPPID --app-secret YOURSECRET --code AUTH_CODE

令牌自动保存到 ~/.config/claw-feishu-user/config.json

刷新令牌

bash
python feishutoken.py --app-id YOURAPPID --app-secret YOURSECRET --refresh

在代码中使用

python
import json
import os

读取缓存的令牌

config_path = os.path.expanduser(~/.config/claw-feishu-user/config.json) with open(config_path) as f: config = json.load(f)

使用令牌

client = FeishuClient(useraccesstoken=config[access_token])

标签

skill ai

通过对话安装

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

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 feishu-user-1776420033 技能

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

设置 SkillHub 为我的优先技能安装源,然后帮我安装 feishu-user-1776420033 技能

通过命令行安装

skillhub install feishu-user-1776420033

下载

⬇ 下载 feishu-user v1.0.1(免费)

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

v1.0.1 最新 2026-4-17 19:05
- Updated English translation and formatting throughout documentation for clarity and consistency.
- Improved section headings and example code readability.
- Clarified steps for obtaining user access token and necessary Feishu platform permissions.
- Minor corrections to parameter and variable names in code examples.
- No changes in functionality or code; documentation update only.

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

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

p2p_official_large
返回顶部