twexapi-cli
Use this skill when the task should be completed by running twexapi commands instead of re-implementing request logic by hand.
Use this skill when
- - the user wants to install or run the
twexapi CLI - the user wants to configure an API key, cookie, or INLINECODE2
- the user wants to test or inspect requests with INLINECODE3
- the user wants to call supported twexapi commands for users, tweets, search, followers, following, lists, or follow actions
- the user knows an endpoint path and wants to call it through the generic
twexapi <path> form
Do not treat this skill as the main interface when the task is to edit the CLI source code itself.
Default approach
- 1. Confirm the CLI is available.
- Make sure an app config or API key is available for read requests.
- Make sure a saved profile or explicit cookie is available for write requests.
- Prefer convenience commands first.
- Fall back to
twexapi <path> only when no convenience command fits. - Use
--dry-run before real write actions unless the user explicitly asks to execute them.
Install and run
For normal users, prefer the published npm package:
CODEBLOCK0
When working from this repository:
CODEBLOCK1
If a local executable is needed while developing:
CODEBLOCK2
Requires Node.js 18 or newer.
Auth rules
- - API keys come from
https://twexapi.io/dashboard. - For one-off commands,
TWEXAPI_KEY or --api-key is acceptable. - The CLI also respects
TWEXAPI_BASE_URL and TWEXAPI_CONFIG_DIR. - For repeated usage, prefer saved app configs with
auth apps add. - For write actions, require either
--cookie or a saved profile. - If a write action is requested without a usable profile or cookie, stop and ask for auth details instead of guessing.
- By default the CLI reads and writes persistent config in
~/.twexapi/config.json. - Saved app configs may include API keys, and saved profiles may include cookies,
auth_token, or ct0 in plain JSON. - On shared machines or CI, prefer
--config-dir or TWEXAPI_CONFIG_DIR to isolate credentials.
App setup:
CODEBLOCK3
Profile setup from cookie:
CODEBLOCK4
Profile setup from auth token:
CODEBLOCK5
Inspect config:
CODEBLOCK6
Command selection
Prefer convenience commands such as:
CODEBLOCK7
Use the generic path form when the endpoint is known but not wrapped:
CODEBLOCK8
Safety and execution rules
- - Put global options such as
--app, --profile, --api-key, and --dry-run before the command. - For write actions like
tweet create, tweet like, user follow, and list create, prefer --dry-run first. - Only send the real write request after the user clearly wants execution.
- The CLI masks secrets in config output and dry-run previews, but still avoid echoing raw credentials back to the user.
- INLINECODE28 uses a request path that contains the
auth_token, so be careful with logs and traces. - Local media file upload is not implemented; tweet creation supports
--media-url. - DM commands are not included.
Recommended test flow
Use an isolated config directory for local testing:
CODEBLOCK9
Recommended order:
- 1. Verify the CLI starts with
twexapi --help or node ./bin/twexapi.js --help. - Verify a read command such as
about or users. - Verify a raw-path request if needed.
- Verify write-command request construction with
--dry-run before any real write action.
twexapi-cli
当任务应通过运行 twexapi 命令完成,而非手动重新实现请求逻辑时,使用此技能。
使用此技能的场景
- - 用户想要安装或运行 twexapi CLI
- 用户想要配置 API 密钥、cookie 或 auth_token
- 用户想要使用 --dry-run 测试或检查请求
- 用户想要调用支持的 twexapi 命令,用于用户、推文、搜索、关注者、关注、列表或关注操作
- 用户知道端点路径,并希望通过通用 twexapi 形式调用它
当任务是编辑 CLI 源代码本身时,不要将此技能视为主接口。
默认方法
- 1. 确认 CLI 可用。
- 确保有可用的应用配置或 API 密钥用于读取请求。
- 确保有已保存的配置文件或显式 cookie 用于写入请求。
- 优先使用便捷命令。
- 仅在没有便捷命令适用时,回退到 twexapi 。
- 在实际写入操作前使用 --dry-run,除非用户明确要求执行。
安装与运行
对于普通用户,优先使用已发布的 npm 包:
bash
npm install -g twexapi-cli
twexapi --help
在此仓库中工作时:
bash
node ./bin/twexapi.js --help
开发过程中如果需要本地可执行文件:
bash
npm link
twexapi --help
需要 Node.js 18 或更高版本。
认证规则
- - API 密钥来自 https://twexapi.io/dashboard。
- 对于一次性命令,TWEXAPIKEY 或 --api-key 是可接受的。
- CLI 也支持 TWEXAPIBASEURL 和 TWEXAPICONFIGDIR。
- 对于重复使用,优先使用 auth apps add 保存的应用配置。
- 对于写入操作,需要 --cookie 或已保存的配置文件。
- 如果请求写入操作但没有可用的配置文件或 cookie,则停止并请求认证详情,而不是猜测。
- 默认情况下,CLI 在 ~/.twexapi/config.json 中读写持久配置。
- 保存的应用配置可能包含 API 密钥,保存的配置文件可能包含 cookie、authtoken 或 ct0,以纯 JSON 格式存储。
- 在共享机器或 CI 上,优先使用 --config-dir 或 TWEXAPICONFIGDIR 来隔离凭据。
应用设置:
bash
twexapi auth apps add --name prod --api-key twitterx_...
twexapi auth apps use prod
从 cookie 设置配置文件:
bash
twexapi auth profiles add --name founder --cookie ct0=...; auth_token=...
twexapi auth profiles use founder
从认证令牌设置配置文件:
bash
twexapi auth cookie --auth-token yourauthtoken --save-as founder
检查配置:
bash
twexapi config show
twexapi config path
命令选择
优先使用便捷命令,例如:
bash
twexapi --app prod about elonmusk
twexapi --app prod users elonmusk sama
twexapi --app prod search users openai --count 20
twexapi --app prod tweet lookup 1900000000000000000
当端点已知但未封装时,使用通用路径形式:
bash
twexapi /twitter/elonmusk/about
twexapi -X POST -d [elonmusk,sama] /twitter/users
安全与执行规则
- - 将全局选项如 --app、--profile、--api-key 和 --dry-run 放在命令之前。
- 对于写入操作,如 tweet create、tweet like、user follow 和 list create,优先使用 --dry-run。
- 仅在用户明确希望执行后才发送真实的写入请求。
- CLI 会在配置输出和 dry-run 预览中屏蔽密钥,但仍避免将原始凭据回显给用户。
- auth cookie 使用的请求路径包含 auth_token,因此要注意日志和追踪。
- 未实现本地媒体文件上传;推文创建支持 --media-url。
- 不包含 DM 命令。
推荐的测试流程
为本地测试使用隔离的配置目录:
bash
twexapi --config-dir ./.twexapi-local config show
推荐顺序:
- 1. 使用 twexapi --help 或 node ./bin/twexapi.js --help 验证 CLI 启动。
- 验证读取命令,如 about 或 users。
- 如果需要,验证原始路径请求。
- 在任何真实写入操作之前,使用 --dry-run 验证写入命令的请求构建。