用 AI 自动化 Twitter:发布、推文串和回复 - Openclaw Skills
作者:互联网
2026-04-17
什么是 Twitter 发布?
Twitter 发布技能是一项强大的集成功能,旨在让 AI 代理能够使用官方 API v2 和 OAuth 1.0a 认证与 Twitter/X 平台进行交互。此工具允许开发人员通过编程方式管理社交媒体,发布单条推文、多部分推文串、回复和引用推文。通过将其纳入您的 Openclaw Skills 库,您可以凭借内置的字符校验和速率限制追踪功能,精准控制社交媒体自动化。
该技能专为可靠性而设计,可处理 Twitter 复杂的加权字符计数系统,确保国际字符和 URL 在提交前格式正确。无论您是构建自动化新闻机器人还是个人助理,此技能都为您本地环境与 X 上的全球对话之间架起必要的桥梁。
下载入口:https://github.com/openclaw/skills/tree/main/skills/sit-in/twitter-post
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install twitter-post
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 twitter-post。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
Twitter 发布 应用场景
- 直接从 CMS 自动分享博客文章或产品更新。
- 从 Markdown 文档创建并发布长篇技术推文串。
- 开发能够实时回复客户咨询或提及的 AI 代理。
- 使用 cron 任务和本地脚本运行预定的社交媒体活动。
- 使用试运行模式测试推文格式和字符限制,无需正式发布。
- 技能通过 OAuth 1.0a 使用四个关键环境变量通过 Twitter/X API 进行身份验证。
- 内容传递给脚本,脚本会自动计算加权字符数(例如,中日韩字符计为 2,URL 计为 23)。
- 如果请求发布推文串,该技能将遍历消息数组,按顺序发布并将其中的每条与前一条推文 ID 相关联。
- 脚本执行指向官方 Twitter v2 端点的 POST 请求。
- 向代理返回 JSON 响应,提供新推文的 URL 以及当前窗口剩余的速率限制配额。
Twitter 发布 配置指南
要将其与您的 Openclaw Skills 集成,请遵循以下安装步骤:
- 从 developer.x.com 获取您的 API Key、API Key Secret、Access Token 和 Access Token Secret。
- 确保您的 Twitter 应用权限设置为 Read and Write。
- 配置您的环境变量:
export TWITTER_CONSUMER_KEY='your_key'
export TWITTER_CONSUMER_SECRET='your_secret'
export TWITTER_ACCESS_TOKEN='your_token'
export TWITTER_ACCESS_TOKEN_SECRET='your_token_secret'
- 如果您所在地区需要代理,请相应设置
HTTPS_PROXY变量。
Twitter 发布 数据架构与分类体系
该技能在每次执行后都会返回一个结构化的 JSON 对象,便于自动化工作流的解析。
| 属性 | 类型 | 描述 |
|---|---|---|
| ok | boolean | API 请求的成功状态 |
| id | string | 已发布推文的唯一数字 ID |
| url | string | x.com 上推文的直接永久链接 |
| remaining | string | 15 分钟窗口内剩余的请求数 |
| limit | string | 当前速率限制窗口的总容量 |
name: twitter-post
description: Post tweets to Twitter/X via the official API v2 (OAuth 1.0a). Use when the user asks to tweet, post to Twitter/X, send a thread, reply to a tweet, or quote tweet. Supports single tweets, threads, replies, and quote tweets with automatic character weight validation.
Twitter Post
Post tweets via the official Twitter/X API v2 using OAuth 1.0a authentication.
Prerequisites
Four environment variables must be set. Obtain them from developer.x.com:
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=
Optional:
HTTPS_PROXY— HTTP proxy URL (e.g.http://127.0.0.1:7897) for regions that need itTWITTER_DRY_RUN=1— validate and print without posting
Setup
Store credentials as env vars. Recommended: add to the OpenClaw instance config or export in shell profile. Never hardcode keys in SKILL.md or scripts.
If the user hasn't set up OAuth yet, guide them:
- Go to developer.x.com → Dashboard → Create App
- Set App permissions to Read and Write
- Go to Keys and tokens tab
- Copy API Key, API Key Secret
- Generate Access Token and Access Token Secret (ensure Read+Write scope)
- If the portal only shows Read, use PIN-based OAuth flow:
- Call
POST /oauth/request_tokenwithoauth_callback=oob - User opens
https://api.twitter.com/oauth/authorize?oauth_token= - User provides the PIN code
- Call
POST /oauth/access_tokenwith the PIN asoauth_verifier
- Call
Usage
All commands via exec. Script path: scripts/tweet.js (relative to this skill directory).
Single tweet
node scripts/tweet.js "Your tweet content here"
Reply to a tweet
node scripts/tweet.js --reply-to 1234567890 "Reply text"
Quote tweet
node scripts/tweet.js --quote 1234567890 "Your commentary"
Thread (multiple tweets)
node scripts/tweet.js --thread "First tweet" "Second tweet" "Third tweet"
Output
JSON to stdout:
{"ok":true,"id":"123456789","url":"https://x.com/i/status/123456789","remaining":"99","limit":"100"}
On error: {"ok":false,"error":"..."}
Character Limits
- Max 280 weighted characters per tweet
- CJK characters (Chinese/Japanese/Korean) count as 2 each
- URLs count as 23 each regardless of length
- Script auto-validates before posting; rejects if over limit
Rate Limits
- 100 tweets / 15 min per user (OAuth 1.0a)
- 3,000 tweets / month on Basic plan ($200/mo)
- Check
remainingfield in output to monitor quota
Tips
- For content from Notion/database: fetch the text first, then pipe to
tweet.js - For cron-based auto-posting: use
execwith env vars set, parse JSON output to confirm success - Thread mode posts sequentially; each tweet auto-replies to the previous one
- Combine
--threadwith--reply-toto attach a thread under an existing tweet
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
从零搭建 AI 智能体:OpenClaw 2.6.2 Windows 一键部署超详细教程
AI 英语教育 APP 的开发
Tokens是什么?AI大模型中的Token是干什么的?开通百炼可以免费领取7000万Tokens
什么是阿里云AI通用型节省计划?AI大模型节省计划Tokens如何计费?
《TikTok 商品详情页前端性能优化实战》
一个客户需求,捅穿了 Anthropic 整套 Agent 架构
Claude 开始进桌面之后,AI 系统的测试边界是不是又变了?
4. OpenClaw 2.6.2 常见问题排查|部署与使用避坑指南
本地 AI 智能体 OpenClaw 2.6.2 环境搭建教程
OpenClaw 2026最新使用手册
AI精选
