X-Publisher

Publish tweets to X (Twitter) using the official Tweepy library. Supports text-only tweets, tweets with images or videos, and returns detailed publish results including tweet ID and URL. Requires X API credentials (API Key, API Secret, Access Token, Access Token Secret).

3,891 stars

Best use case

X-Publisher is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Publish tweets to X (Twitter) using the official Tweepy library. Supports text-only tweets, tweets with images or videos, and returns detailed publish results including tweet ID and URL. Requires X API credentials (API Key, API Secret, Access Token, Access Token Secret).

Teams using X-Publisher should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/x-publisher/SKILL.md --create-dirs "https://raw.githubusercontent.com/openclaw/skills/main/skills/alphafactor/x-publisher/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/x-publisher/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How X-Publisher Compares

Feature / AgentX-PublisherStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Publish tweets to X (Twitter) using the official Tweepy library. Supports text-only tweets, tweets with images or videos, and returns detailed publish results including tweet ID and URL. Requires X API credentials (API Key, API Secret, Access Token, Access Token Secret).

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# X (Twitter) 推文发布工具

使用官方 Tweepy 库发布推文,支持纯文本、图片、视频等多种媒体类型。

## 功能特性

- 📝 **纯文本推文** - 快速发布文字内容
- 🖼️ **图片支持** - 支持 JPG、PNG、GIF、WebP 格式(最多4张)
- 🎬 **视频支持** - 支持 MP4、MOV、AVI、WebM 格式
- 📊 **返回结果** - 返回推文 ID、链接、发布时间等详细信息
- ✅ **认证验证** - 支持验证 API 凭证是否有效

## 前提条件

### 1. 安装依赖

```bash
pip3 install tweepy --user
```

### 2. 获取 X API 凭证

1. 访问 https://developer.twitter.com/en/portal/dashboard
2. 创建项目并生成 API 密钥
3. 获取以下凭证:
   - API Key
   - API Secret
   - Access Token
   - Access Token Secret

### 3. 配置环境变量

```bash
# 添加到 ~/.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"  # 可选
```

然后执行:
```bash
source ~/.zshrc
```

## 使用方法

### 验证认证信息

首次使用前,建议先验证凭证:

```bash
python3 scripts/x_publisher.py verify
```

输出示例:
```
✅ 认证成功!
👤 用户名: @your_username
📛 显示名: Your Name
👥 粉丝: 1,234
📝 推文: 5,678
```

### 发布纯文本推文

```bash
python3 scripts/x_publisher.py tweet "Hello, X! This is my first tweet."
```

### 发布带图片的推文

```bash
# 单张图片
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
```

### 发布带视频的推文

```bash
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` |

### tweet 命令参数

| 参数 | 简写 | 说明 | 必填 |
|------|------|------|------|
| `text` | - | 推文内容 | 是 |
| `--media` | `-m` | 媒体文件路径 | 否 |

## 支持的媒体格式

### 图片
- **JPG/JPEG** - 推荐格式
- **PNG** - 支持透明背景
- **GIF** - 支持动画
- **WebP** - 现代格式

**限制**:
- 最多 4 张图片
- 单张图片最大 5MB

### 视频
- **MP4** - 推荐格式
- **MOV** - QuickTime 格式
- **AVI** - 常见格式
- **WebM** - 现代格式

**限制**:
- 单个视频最大 512MB
- 最长 2 分 20 秒

## 错误处理

### 认证失败

```
❌ 认证失败: 无法获取用户信息
```

**解决方法**:
- 检查 API 密钥和令牌是否正确
- 确认令牌未过期
- 检查网络连接

### 权限不足

```
❌ 推文发布失败
错误类型: 权限不足
错误信息: You are not allowed to create a Tweet with these settings
```

**解决方法**:
- 确认应用有 "Write" 权限
- 检查是否违反 X 平台规则

### 请求过于频繁

```
❌ 推文发布失败
错误类型: 请求过于频繁
错误信息: Rate limit exceeded
```

**解决方法**:
- 等待几分钟后重试
- X API 有速率限制(每15分钟300条推文)

### 媒体上传失败

```
❌ 媒体文件不存在: /path/to/image.jpg
```

**解决方法**:
- 检查文件路径是否正确
- 确认文件格式支持
- 检查文件大小是否超限

## 使用场景

### 场景1:自动化发布

```bash
# 发布每日摘要
python3 scripts/x_publisher.py tweet "📊 今日市场摘要:BTC $43,250 (+2.3%)" 
```

### 场景2:带图发布

```bash
# 发布截图或图表
python3 scripts/x_publisher.py tweet "📈 今日走势图" --media ~/charts/btc_today.png
```

### 场景3:批量发布脚本

```python
#!/bin/bash
# publish_news.sh

CONTENT="🚀 重大新闻:..."
IMAGE="/path/to/news_image.jpg"

python3 scripts/x_publisher.py tweet "$CONTENT" --media "$IMAGE"
```

### 场景4:集成到其他工具

```python
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']}")
```

## API 限制

| 限制类型 | 数值 | 说明 |
|----------|------|------|
| 推文长度 | 280 字符 | 超过将自动截断 |
| 媒体数量 | 4 个 | 图片或视频混合 |
| 图片大小 | 5 MB | 单张图片 |
| 视频大小 | 512 MB | 单个视频 |
| 视频时长 | 2分20秒 | 最大时长 |
| 发布频率 | 300条/15分钟 | 速率限制 |

## 注意事项

1. **凭证安全** - 不要泄露 API 密钥,使用环境变量存储
2. **内容合规** - 遵守 X 平台规则,避免发布违规内容
3. **频率控制** - 注意 API 速率限制,避免频繁发布
4. **媒体版权** - 确保上传的媒体文件有版权或使用授权

## 参考

- Tweepy 文档: https://docs.tweepy.org/
- X API 文档: https://developer.twitter.com/en/docs/twitter-api
- X Developer Portal: https://developer.twitter.com/en/portal/dashboard

Related Skills

nansen-binance-publisher

3891
from openclaw/skills

Automatically fetch multi-dimensional on-chain data using Nansen CLI, compile a comprehensive and beautifully formatted daily report, and publish it to Binance Square. Auto-run on messages like 'generate nansen daily report', 'post nansen daily to square', or when the user triggers the slash commands `/nansen` or `/post_square`.

Content & Documentation

wechat-publisher

3891
from openclaw/skills

一键发布 Markdown 到微信公众号草稿箱。基于 wenyan-cli,支持多主题、代码高亮、图片自动上传。

Content & Documentation

mastodon-publisher

3891
from openclaw/skills

Publish content to Mastodon. Use when you need to post a Mastodon status.

weibo-publisher

3891
from openclaw/skills

Publish posts to Weibo (Sina Weibo) using browser automation. Use when the user wants to post content to Weibo, share updates on Weibo, publish microblogs, or automate Weibo posting. Supports text posts with emoji, hashtags, and mentions. No API key required - uses browser automation with managed browser profile.

wordpress-publisher

3891
from openclaw/skills

Publish content directly to WordPress sites via REST API with full Gutenberg block support. Create and publish posts/pages, auto-load and select categories from website, generate SEO-optimized tags, preview articles before publishing, and generate Gutenberg blocks for tables, images, lists, and rich formatting. Use when user wants to publish to WordPress, post to blog, create WordPress article, update WordPress post, or convert markdown to Gutenberg blocks.

clawhub-publisher

3891
from openclaw/skills

将本地 skill 目录发布到 clawhub.com 的自动化发布助手。 当用户说"发布这个 skill 到 clawhub"、"把 XX skill 上传到 clawhub"、 "clawhub publish"、"发布到 clawhub" 等时触发。 自动处理:token 验证、CLI bug patch、slug 冲突、频率限制重试。

publisher-identity-verifier

3891
from openclaw/skills

Helps verify publisher identity integrity in AI agent ecosystems. Detects impersonation, key rotation anomalies, and identity gaps in the trust chain between skill publishers and their claimed identities.

content-creation-publisher

3891
from openclaw/skills

content-creation-publisher - 从云端仓库同步的技能

video-publisher-pro

3891
from openclaw/skills

根据IP背景和视频文案,为短视频生成一套完整的发布策略,包括发布时间、话题标签、封面文案和发布标题,并能将文案合成为封面图。

wechat-xhs-publisher

3891
from openclaw/skills

微信公众号与小红书一键发布工具。当需要将热点新闻改写成公众号文章并发布到微信公众号和小红书时使用,包括:1)根据热点新闻改写公众号文章 2)使用AI生成文章配图 3)发布前IP检测 4)发布到微信公众号 5)发布到小红书。触发场景:热点新闻发布、公众号文章发布、小红书种草、社交媒体同步发布。

skill-publisher-claw-skill

3891
from openclaw/skills

Prepare Claw skills for public release. Use when publishing skills to GitHub or ClawdHub - covers security audit, portability, documentation, git hygiene. Triggers: publish skill, release skill, audit skill, skill checklist, prepare skill for release.

auto-publisher

3891
from openclaw/skills

Multi-platform video auto-publisher. Automatically upload videos to Douyin, WeChat Channels, Xiaohongshu, Bilibili, YouTube and more. Supports batch publishing, scheduled posting, auto-caption generation, and hashtag optimization.