微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🐦

直连 X 官方 API,安全发帖无代理

X OAuth API · v1.1.0
效率 安全 B 级 作者 ngmeyer 公开目录收录
下载 2k 安装 2 收藏 5.6k 浏览 19
原始页面

简介

通过官方 X API OAuth 1.0a 直接发布推文、管理话题串、查询账号信息,免费层级可用,无需第三方代理。

原始描述

Post to X (Twitter) using the official OAuth 1.0a API. Use when asked to "post to X", "tweet this", "post on Twitter", create threads, delete tweets, or chec...

中文使用说明 来自收录源

核心用法

x-oauth-api 是一个基于官方 X API v2 的 CLI 工具,支持通过 OAuth 1.0a 认证直接与 X(原 Twitter)平台交互。主要功能包括:

  • 发布推文:x post "内容",支持回复、引用和媒体附件
  • 创建话题串:x thread "第一条" "第二条" ... 自动串联多条推文
  • 账号管理:x me 查看当前账号信息,x delete <id> 删除推文
  • 提及与搜索:x mentions 和 x search(需 Basic+ 付费层级)

显著优点

  1. 官方直连:不依赖第三方代理,数据不经过中间服务器,隐私可控
  2. 免费层级友好:基础发布、删除、账号查询功能完全免费
  3. 标准 OAuth 1.0a:使用官方认证流程,Token 由用户自行管理
  4. 透明计费:X 官方定价清晰,无隐藏费用

潜在局限

  • 功能分层严格:搜索、提及获取、媒体上传等核心功能需 Basic+ 层级($100/月),免费层级仅限于「写」操作
  • 环境变量敏感:需妥善保管 4 组 OAuth 凭证,泄露即导致账号风险
  • Rate Limit 较严:发布限制 200 条/15 分钟,自动化场景易触发限流
  • 无内容审核过滤:直接发布,需用户自行把控内容合规性

适合人群

  • 需要程序化管理 X 账号的内容创作者、社交运营团队
  • 构建自动化工作流(如 AI Agent 联动发帖)的开发者
  • 注重数据隐私、不愿使用第三方 Twitter 客户端的用户

常规风险

风险类型 说明
凭证泄露 OAuth Token 若写入日志或代码仓库,可能导致账号被盗用
误操作发布 CLI 直接执行,无二次确认,测试环境易误发正式账号
限流封禁 高频发布可能触发 X 平台风控,导致临时或永久限制
付费陷阱 误调用搜索/媒体接口将直接报错,需明确区分免费/付费边界

配置要点

需从 X Developer Portal 获取并配置 4 项环境变量:X_API_KEY、X_API_SECRET、X_ACCESS_TOKEN、X_ACCESS_TOKEN_SECRET,且务必确保无尾随换行符。

技能正文


name: x-oauth-api description: Post to X (Twitter) using the official OAuth 1.0a API. Use when asked to "post to X", "tweet this", "post on Twitter", create threads, delete tweets, or check account info. Free tier compatible. NOT for search, mentions, or media uploads (requires Basic+ tier). metadata: { "openclaw": { "requires": { "env": ["X_API_KEY", "X_API_SECRET", "X_ACCESS_TOKEN", "X_ACCESS_TOKEN_SECRET"] } } }

X OAuth API Skill

Post to X (formerly Twitter) using the official X API with OAuth 1.0a authentication.

Overview

This skill provides direct access to X API v2 for posting tweets, managing threads, and monitoring mentions. No proxy or third-party service required — uses your X API credentials directly.

Use when:

  • User says "post to X", "tweet this", "post on Twitter"
  • Need to create threads or media posts
  • Want to check mentions or engage with replies

Quick Start

1. Configure X API Credentials

Store these environment variables (from your X Developer Account):

X_API_KEY              # Consumer Key (API Key)
X_API_SECRET           # Consumer Secret
X_ACCESS_TOKEN         # Access Token
X_ACCESS_TOKEN_SECRET  # Access Token Secret
X_USER_ID              # Optional: Your numeric user ID (speeds up mentions)

Free Tier vs Paid Tier

Free tier supports:

  • ✅ Posting tweets and threads
  • ✅ Deleting tweets
  • ✅ Account info lookup (x me)

Requires Basic+ tier:

  • 🔒 Search tweets
  • 🔒 Fetch mentions
  • 🔒 Media uploads

2. Basic Usage

# Post a simple tweet
x post "Hello from X API"

# Post a thread
x thread "First tweet" "Second tweet" "Third tweet"

# Check mentions
x mentions --limit 10

# Search recent tweets
x search "AI agents" --limit 5

Commands

x post <text>

Post a single tweet.

Options:

  • --reply-to <tweet-id> - Reply to a specific tweet
  • --quote <tweet-id> - Quote tweet
  • --media <file> - Attach image/video

x thread <tweet1> <tweet2> ...

Post a tweet thread.

x mentions [options]

Get recent mentions of your account.

Options:

  • --limit <n> - Number of mentions (default: 10, max: 100)
  • --since <tweet-id> - Only mentions after this ID
  • --format json - Output as JSON

x search <query> [options]

Search recent tweets.

Options:

  • --limit <n> - Number of results (default: 10, max: 100)
  • --format json - Output as JSON

x delete <tweet-id>

Delete a tweet.

x me

Show current account info (name, username, follower counts, user ID).

API Rate Limits

Endpoint Limit Window
POST /2/tweets 200 15 min (Free tier)
GET /2/tweets/search/recent 100 15 min (Free tier)
GET /2/users/:id/mentions 100 15 min (Free tier)

Rate limits vary by access tier. See X API documentation for details.

Authentication

OAuth 1.0a is handled transparently. Just provide your credentials via environment variables. The skill will sign all requests automatically.

Troubleshooting

"Unauthorized" error

  • Check X API credentials are correct
  • Verify credentials are set in environment
  • Ensure your app has write permissions in X Developer Portal

"Rate limit exceeded"

  • Wait 15 minutes for limit to reset
  • Reduce request frequency

"This endpoint requires a paid X API tier"

  • Search and mentions require Basic+ tier on X API
  • Free tier only supports posting, deleting, and account lookup

Requirements

  • X Developer Account with API access
  • OAuth 1.0a credentials configured
  • Network access to api.twitter.com

Cost

Free. X API is free for basic usage. Check your app's rate limits in X Developer Portal.

Gotchas

  • Free tier only supports posting, deleting, and account lookup — search, mentions, and media uploads require Basic+ tier ($100/month). Don't attempt these on free tier; you'll get a clear "requires paid tier" error.
  • "Unauthorized" after credential rotation — X API keys are invalidated when you regenerate them in the Developer Portal. All 4 env vars must be updated together (X_API_KEY, X_API_SECRET, X_ACCESS_TOKEN, X_ACCESS_TOKEN_SECRET).
  • Trailing newlines in env vars break auth — If you copy/paste credentials and include a trailing \n, OAuth signing will fail silently with a 401. Always verify with echo -n "$X_API_KEY" | xxd to confirm no whitespace.
  • Rate limit 429s are per-endpoint — Hitting the limit on POST /2/tweets doesn't affect GET /2/users. Each endpoint has its own 15-minute window. Back off only the failing endpoint.
  • App write permissions must be set before generating tokens — If you generate access tokens before enabling "Read and Write" in the Developer Portal, the tokens will be read-only. Regenerate tokens after changing permissions.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

其他来源收录

同一技能在不同目录的原始页面:

标签

social-mediax-apitwitteroauthcontent-publishingcli-toolapi-client

同类 Skill