运行时依赖
安装命令
点击复制技能文档
Feishishu document operations using useru User
Fe 访问 令牌 authentication. Call Feishu Open API directly via REST API.
安装 Dependencies pip 安装 请求s
Quick 启动 from feishu_命令行工具ent 导入 Feishu命令行工具ent
# 初始化 命令行工具ent 命令行工具ent = Feishu命令行工具ent(user_访问_令牌="u-xxx")
获取 User 访问 令牌 Step 1: 获取 应用 凭证s from Feishu Open 平台
Prepare the following:
应用_ID - 应用 ID (from Feishu Open 平台 应用 设置tings) 应用_SECRET - 应用 Secret (from Feishu Open 平台 应用 设置tings) REDIRECT_URI - Authorization callback URL
Enable these 权限s:
docx:document - Document operations drive:drive.搜索:readonly - Cloud drive 搜索 搜索:docs:read - Document 搜索 Step 2: 生成 Authorization URL https://accounts.feishu.cn/open-APIs/authen/v1/授权?命令行工具ent_id={YOUR_应用_ID}&响应_type=code&redirect_uri={YOUR_REDIRECT_URI}&scope=docx%3Adocument%20drive%3Adrive.搜索%3Areadonly%20搜索%3Adocs%3Aread
Step 3: Exchange for 令牌 curl -X POST "https://open.feishu.cn/open-APIs/authen/v1/访问_令牌" \ -H "Content-Type: 应用/json" \ -d '{ "grant_type": "authorization_code", "code": "{YOUR_CODE}", "应用_id": "{YOUR_应用_ID}", "应用_secret": "{YOUR_应用_SECRET}" }'
The returned 访问_令牌 is your user_访问_令牌.
Usage Examples from feishu_命令行工具ent 导入 Feishu命令行工具ent
# 初始化 命令行工具ent = Feishu命令行工具ent(user_访问_令牌="u-xxx")
# Read document content = 命令行工具ent.read_doc("doc_令牌") print(content)
# 创建 document new_令牌 = 命令行工具ent.创建_doc("My New Document") print(f"New document: {new_令牌}")
# Write document 命令行工具ent.write_doc("doc_令牌", "# Title\n\nContent")
# 应用end content 命令行工具ent.应用end_doc("doc_令牌", "## New Section\n\nMore content")
# 列出 all blocks blocks = 命令行工具ent.列出_blocks("doc_令牌") for block in blocks: print(block)
# 获取 specific block block = 命令行工具ent.获取_block("doc_令牌", "block_id")
# 更新 block 命令行工具ent.更新_block("doc_令牌", "block_id", "New content")
# 删除 block 命令行工具ent.删除_block("doc_令牌", "block_id")
Convenience Functions
Don't want to 创建 a 命令行工具ent? Use functions directly:
from feishu_命令行工具ent 导入 read_document, 创建_document, write_document, 应用end_document
# Read content = read_document("doc_令牌", user_访问_令牌="u-xxx")
# 创建 new_令牌 = 创建_document("Title", user_访问_令牌="u-xxx")
# Write write_document("doc_令牌", "# Content", user_访问_令牌="u-xxx")
# 应用end 应用end_document("doc_令牌", "## More", user_访问_令牌="u-xxx")
API Reference Feishu命令行工具ent Method Description read_doc(doc_令牌) Read document content 创建_doc(title, folder_令牌) 创建 new document write_doc(doc_令牌, content) Write document (overwrite) 应用end_doc(doc_令牌, content) 应用end content to end 列出_blocks(doc_令牌) 列出 all blocks 获取_block(doc_令牌, block_id) 获取 specific block 更新_block(doc_令牌, block_id, content) 更新 block content 删除_block(doc_令牌, block_id) 删除 block Notes user_访问_令牌 has an expiration time, needs periodic refresh The scope in authorization URL must be enabled in Feishu Open 平台 This 技能 访问es personal cloud documents using user 身份 Related Links Feishu Open 平台: https://open.feishu.cn Document API: https://open.feishu.cn/document/ukTMukTMukTM/uADOwUjLwgDMzCM4ATm 令牌 Auto Refresh
Use feishu_令牌.py script for automatic 令牌 refresh.
安装 Dependencies pip 安装 请求s
First Authorization # 1. 生成 authorization URL python feishu_令牌.py --应用-id YOUR_应用_ID --应用-secret YOUR_SECRET --redirect-uri YOUR_REDIRECT_URI --url
After user 授权s, will callback to YOUR_REDIRECT_URI?code=XXX
# 2. Use authorization code to 获取 令牌 python feishu_令牌.py --应用-id YOUR_应用_ID --应用-secret YOUR_SECRET --code AUTH_CODE
令牌 is automatically saved to ~/.config/claw-feishu-user/config.json
Refresh 令牌 python feishu_令牌.py --应用-id YOUR_应用_ID --应用-secret YOUR_SECRET --refresh
In Code 导入 json 导入 os
# Read 缓存d 令牌 config_path = os.path.expanduser("~/.config/claw-feishu-user/config.json") with open(config_path) as f: config = json.load(f)
# Use 令牌 命令行工具ent = Feishu命令行工具ent(user_访问_令牌=config["访问_令牌"])