支持抖音开放平台官方 OpenAPI 的命令行工具。
Project description
douyin-cli
面向抖音开放平台官方 OpenAPI 的命令行工具,提供 OAuth 授权、token 管理、常用官方接口封装和通用 OpenAPI 请求能力。
功能
- 官方 OAuth 授权链接生成、code 换 token、token 刷新
- 官方
client_token、access_token管理 - 授权用户信息查询
- 官方评论列表、评论回复列表、评论回复
- 企业号私信消息发送
- 任意官方 OpenAPI 路径请求
- 可选本地字幕生成
- Obscura/自动化运行时集成
安装
作为 Python 库安装:
uv add douyin-cli
命令行安装:
uv tool install douyin-cli
开发安装:
uv tool install -e .
uv tool install -e '.[subtitle-mac]'
字幕可选依赖:
uv tool install 'douyin-cli[subtitle]'
uv tool install 'douyin-cli[subtitle-cuda]'
uv tool install 'douyin-cli[subtitle-mac]'
Python 库调用示例:
from douyin_cli.douyin import Douyin
from douyin_cli.douyin.openapi import DouyinOpenAPIClient
with DouyinOpenAPIClient() as client:
token_data = client.client_token("client_key", "client_secret")
douyin = Douyin(target="搜索关键词", type="search", limit=5, cookie="sessionid=...")
douyin.run()
Agent Skill
安装本仓库配套 skill:
bunx skills add LIghtJUNction/douyin -g
npx skills add LIghtJUNction/douyin -g
官方 OAuth 接入
准备抖音开放平台应用的 client_key、client_secret、回调地址和所需 scope。
douyin auth login \
--client-key "$DOUYIN_CLIENT_KEY" \
--client-secret "$DOUYIN_CLIENT_SECRET" \
--redirect-uri "https://example.com/callback" \
--scope user_info \
--scope item.comment
命令会输出官方授权链接。用户授权后,将回调中的 code 保存为 token:
douyin auth code --code "授权码"
也可以一步完成:
douyin auth login \
--client-key "$DOUYIN_CLIENT_KEY" \
--client-secret "$DOUYIN_CLIENT_SECRET" \
--redirect-uri "https://example.com/callback" \
--scope user_info \
--code "授权码"
检查和刷新授权:
douyin auth status
douyin auth refresh
douyin auth logout
授权后,官方 OpenAPI 命令会自动读取已保存的 token 和 open_id,自动化调用不需要重复传参:
douyin api userinfo
douyin api comment-list --item-id "$DOUYIN_ITEM_ID"
Obscura 集成
douyin 提供稳定的 JSON 输出和集成 manifest,Obscura 可以直接发现命令能力并调用官方 OpenAPI。
douyin obscura manifest
douyin obscura status
douyin auth status --json
推荐接入顺序:
douyin auth login \
--client-key "$DOUYIN_CLIENT_KEY" \
--client-secret "$DOUYIN_CLIENT_SECRET" \
--redirect-uri "https://example.com/callback" \
--scope user_info
douyin auth code --code "授权码"
douyin auth status --json
官方 OpenAPI
douyin api client-token \
--client-key "$DOUYIN_CLIENT_KEY" \
--client-secret "$DOUYIN_CLIENT_SECRET"
douyin api userinfo \
--token "$DOUYIN_ACCESS_TOKEN" \
--open-id "$DOUYIN_OPEN_ID"
douyin api comment-list \
--token "$DOUYIN_ACCESS_TOKEN" \
--open-id "$DOUYIN_OPEN_ID" \
--item-id "$DOUYIN_ITEM_ID"
douyin api comment-reply \
--token "$DOUYIN_ACCESS_TOKEN" \
--open-id "$DOUYIN_OPEN_ID" \
--item-id "$DOUYIN_ITEM_ID" \
--comment-id "$DOUYIN_COMMENT_ID" \
--content "谢谢反馈"
企业号私信发送需要应用已开通 enterprise.im 权限,并从私信事件回调中拿到接收方 to_user_id:
douyin auth login \
--client-key "$DOUYIN_CLIENT_KEY" \
--client-secret "$DOUYIN_CLIENT_SECRET" \
--redirect-uri "https://example.com/callback" \
--scope enterprise.im
douyin api im-message-send \
--to-user-id "$DOUYIN_TO_USER_ID" \
--text "你好,已收到" \
--yes
通用请求:
douyin api request GET /oauth/userinfo/ \
--token "$DOUYIN_ACCESS_TOKEN" \
--param open_id="$DOUYIN_OPEN_ID"
本地字幕
douyin subtitle video.mp4 --language zh
douyin subtitle video.mp4 --model Qwen/Qwen3-ASR-1.7B --format srt
首次使用模型时会自动从 Hugging Face 下载。CUDA 模式需要 CUDA 12 运行库;如果系统只提供 CUDA 13,可安装 douyin-cli[subtitle-cuda],或使用 CPU 模式:
douyin subtitle video.mp4 --device cpu --compute-type int8 --language zh
macOS Apple Silicon 可安装 MLX 后端使用本机 GPU:
uv tool install 'douyin-cli[subtitle-mac]'
douyin subtitle video.mp4 --backend mlx-whisper --language zh
--backend auto 会在 macOS arm64 上优先使用 mlx-whisper,其他平台默认使用 qwen-asr 和 Qwen/Qwen3-ASR-1.7B。如需旧的 Whisper 路径,可显式使用 --backend faster-whisper --model Systran/faster-whisper-small。--compute-type 只影响 faster-whisper 后端。
环境变量
DOUYIN_CLIENT_KEYDOUYIN_CLIENT_SECRETDOUYIN_ACCESS_TOKEN
技术栈
- Python 3.13
- Click
- niquests
- uv / uv-build
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file douyin_cli-2026.5.31.1.tar.gz.
File metadata
- Download URL: douyin_cli-2026.5.31.1.tar.gz
- Upload date:
- Size: 51.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90bf4771e12fb945e20d49b370b926c3693d89fc6a0ba44fc89aa8476b6fbcc1
|
|
| MD5 |
35a1fc00186b051cde720dcf693aed70
|
|
| BLAKE2b-256 |
9c086e0b0dd31d67a98bf1e741b21069bdb4bd56cae719c780e174503634f9b3
|
File details
Details for the file douyin_cli-2026.5.31.1-py3-none-any.whl.
File metadata
- Download URL: douyin_cli-2026.5.31.1-py3-none-any.whl
- Upload date:
- Size: 65.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
809804c81c79676e7c4ff6eadcc2cc1252c9feb86094e5b7dbfb887e9afd4dc4
|
|
| MD5 |
621ca3e255fc276b454ceef49ed9b4ea
|
|
| BLAKE2b-256 |
c8f3723c19ac34bd58992a7167123c1b352c276474228f211f3fa0606cf8c40c
|