Install
openclaw skills install x-publisherPublish tweets to X (Twitter) using the official Tweepy library. Supports text-only tweets, tweets with images or videos, and returns detailed publish result...
openclaw skills install x-publisher使用官方 Tweepy 库发布推文,支持纯文本、图片、视频等多种媒体类型。
pip3 install tweepy --user
# 添加到 ~/.zshrc
export X_API_KEY="your-api-key"
export X_API_SECRET="your-api-secret"
export X_ACCESS_TOKEN="your-access-token"
export X_ACCESS_TOKEN_SECRET="your-access-token-secret"
export X_BEARER_TOKEN="your-bearer-token" # 可选
然后执行:
source ~/.zshrc
首次使用前,建议先验证凭证:
python3 scripts/x_publisher.py verify
输出示例:
✅ 认证成功!
👤 用户名: @your_username
📛 显示名: Your Name
👥 粉丝: 1,234
📝 推文: 5,678
python3 scripts/x_publisher.py tweet "Hello, X! This is my first tweet."
# 单张图片
python3 scripts/x_publisher.py tweet "Check out this photo!" --media /path/to/image.jpg
# 多张图片(最多4张)
python3 scripts/x_publisher.py tweet "My photo collection:" \
--media /path/to/photo1.jpg \
--media /path/to/photo2.png \
--media /path/to/photo3.gif
python3 scripts/x_publisher.py tweet "Watch this video!" --media /path/to/video.mp4
发布成功后会返回:
============================================================
✅ 推文发布成功!
============================================================
📝 推文 ID: 1234567890123456789
🔗 链接: https://twitter.com/user/status/1234567890123456789
⏰ 发布时间: 2024-02-03T15:30:45.123456
📄 内容预览: Hello, X! This is my first tweet.
============================================================
📋 JSON 输出:
{
"success": true,
"tweet_id": "1234567890123456789",
"text": "Hello, X! This is my first tweet.",
"created_at": "2024-02-03T15:30:45.123456",
"url": "https://twitter.com/user/status/1234567890123456789"
}
| 命令 | 功能 | 示例 |
|---|---|---|
verify | 验证认证 | x_publisher.py verify |
tweet | 发布推文 | x_publisher.py tweet "Hello" --media photo.jpg |
| 参数 | 简写 | 说明 | 必填 |
|---|---|---|---|
text | - | 推文内容 | 是 |
--media | -m | 媒体文件路径 | 否 |
限制:
限制:
❌ 认证失败: 无法获取用户信息
解决方法:
❌ 推文发布失败
错误类型: 权限不足
错误信息: You are not allowed to create a Tweet with these settings
解决方法:
❌ 推文发布失败
错误类型: 请求过于频繁
错误信息: Rate limit exceeded
解决方法:
❌ 媒体文件不存在: /path/to/image.jpg
解决方法:
# 发布每日摘要
python3 scripts/x_publisher.py tweet "📊 今日市场摘要:BTC $43,250 (+2.3%)"
# 发布截图或图表
python3 scripts/x_publisher.py tweet "📈 今日走势图" --media ~/charts/btc_today.png
#!/bin/bash
# publish_news.sh
CONTENT="🚀 重大新闻:..."
IMAGE="/path/to/news_image.jpg"
python3 scripts/x_publisher.py tweet "$CONTENT" --media "$IMAGE"
import subprocess
import json
result = subprocess.run(
['python3', 'scripts/x_publisher.py', 'tweet', 'Hello!', '--media', 'photo.jpg'],
capture_output=True,
text=True
)
# 解析 JSON 输出
output_lines = result.stdout.split('\n')
for line in output_lines:
if line.strip().startswith('{'):
tweet_info = json.loads(line)
print(f"Tweet ID: {tweet_info['tweet_id']}")
print(f"URL: {tweet_info['url']}")
| 限制类型 | 数值 | 说明 |
|---|---|---|
| 推文长度 | 280 字符 | 超过将自动截断 |
| 媒体数量 | 4 个 | 图片或视频混合 |
| 图片大小 | 5 MB | 单张图片 |
| 视频大小 | 512 MB | 单个视频 |
| 视频时长 | 2分20秒 | 最大时长 |
| 发布频率 | 300条/15分钟 | 速率限制 |
X_API_KEYrequiredX_API_SECRETrequiredX_ACCESS_TOKENrequiredX_ACCESS_TOKEN_SECRETrequiredX_BEARER_TOKENrequired