Agent skill

X API

by affaan-m in affaan-m/ECC

X/Twitter API集成,用于发布推文、线程、读取时间线、搜索和分析。涵盖OAuth认证模式、速率限制和平台原生内容发布。当用户希望以编程方式与X交互时使用。

MITAuto-check: notesBackend & APIs

Install X API

skills CLI
$ npx skills add affaan-m/ECC --skill x-api -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install affaan-m/ECC x-api --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/affaan-m/ECC.git skills-src && mkdir -p .claude/skills && cp -r skills-src/docs/zh-CN/skills/x-api .claude/skills/x-api && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
x-api
GitHub stars
276k
Used in
2 other repos
Token cost
~1.1k tokens
SKILL.md length
101 words
Files
1
Skills in repo
673
Repo updated
First seen
Licence
MIT

At a glance

X/Twitter API集成,用于发布推文、线程、读取时间线、搜索和分析。涵盖OAuth认证模式、速率限制和平台原生内容发布。当用户希望以编程方式与X交互时使用。

  • Works in 4 steps: 使用内容引擎生成内容(X 平台格式) → 验证长度(单条推文 280 字符) → 使用上述模式通过 X API 发布 → …
  • Tasks that involve OAuth and OpenID Connect
  • SKILL.md covers 何时激活, 认证, 核心操作 and 速率限制, plus 4 more sections
  • Reaches api.x.com and upload.twitter.com; needs X_BEARER_TOKEN and X_API_KEY

What it does

X API is an agent skill from affaan-m/ECC. X/Twitter API集成,用于发布推文、线程、读取时间线、搜索和分析。涵盖OAuth认证模式、速率限制和平台原生内容发布。当用户希望以编程方式与X交互时使用。

Its SKILL.md is about 1.1k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering OAuth and OpenID Connect. It works with X (Twitter). The repository describes itself as: The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond. The licence is MIT.

When your agent uses it

  • Tasks that involve OAuth and OpenID Connect

Example prompts

  • “/x-api”

Requirements

  • Python 3
  • A credential in X_BEARER_TOKEN
  • A credential in X_API_KEY

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. 使用内容引擎生成内容(X 平台格式)
  2. 验证长度(单条推文 280 字符)
  3. 使用上述模式通过 X API 发布
  4. 通过 public_metrics 跟踪参与度

What it can do on your machine

Read from SKILL.md and the folder at commit ef648e0. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are python and bash).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • api.x.com
    • upload.twitter.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • X_BEARER_TOKEN
    • X_API_KEY
    • X_API_SECRET
    • X_ACCESS_TOKEN
    • X_ACCESS_SECRET

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

X API loads about 1.1k tokens when it runs. Until then it costs about 22 tokens; SKILL.md has 101 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~22
When it runs · the whole SKILL.md, loaded when a task matches
~1.1k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NoteMentions a .env fileSKILL.md:192
    * **切勿硬编码令牌。** 使用环境变量或 `.env` 文件。
  • NoteMentions a .env fileSKILL.md:193
    * **切勿提交 `.env` 文件。** 将其添加到 `.gitignore`。

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from affaan-m/ECC at commit ef648e0, republished under its MIT licence (© affaan-m). 101 words, ~1,096 tokens.

Download SKILL.mdSave it as .claude/skills/x-api/SKILL.md (or your agent's skills folder).
name
x-api
description
X/Twitter API集成,用于发布推文、线程、读取时间线、搜索和分析。涵盖OAuth认证模式、速率限制和平台原生内容发布。当用户希望以编程方式与X交互时使用。
origin
ECC

X API

以编程方式与 X(Twitter)交互,用于发布、读取、搜索和分析。

何时激活

  • 用户希望以编程方式发布推文或帖子串
  • 从 X 读取时间线、提及或用户数据
  • 在 X 上搜索内容、趋势或对话
  • 构建 X 集成或机器人
  • 分析和参与度跟踪
  • 用户提及"发布到 X"、"发推"、"X API"或"Twitter API"

认证

OAuth 2.0 Bearer 令牌(仅应用)

最佳适用场景:读取密集型操作、搜索、公开数据。

bash
# Environment setup
export X_BEARER_TOKEN="your-bearer-token"
python
import os
import requests

bearer = os.environ["X_BEARER_TOKEN"]
headers = {"Authorization": f"Bearer {bearer}"}

# Search recent tweets
resp = requests.get(
    "https://api.x.com/2/tweets/search/recent",
    headers=headers,
    params={"query": "claude code", "max_results": 10}
)
tweets = resp.json()
OAuth 1.0a(用户上下文)

必需用于:发布推文、管理账户、私信。

bash
# Environment setup — source before use
export X_API_KEY="your-api-key"
export X_API_SECRET="your-api-secret"
export X_ACCESS_TOKEN="your-access-token"
export X_ACCESS_SECRET="your-access-secret"
python
import os
from requests_oauthlib import OAuth1Session

oauth = OAuth1Session(
    os.environ["X_API_KEY"],
    client_secret=os.environ["X_API_SECRET"],
    resource_owner_key=os.environ["X_ACCESS_TOKEN"],
    resource_owner_secret=os.environ["X_ACCESS_SECRET"],
)

核心操作

发布一条推文
python
resp = oauth.post(
    "https://api.x.com/2/tweets",
    json={"text": "Hello from Claude Code"}
)
resp.raise_for_status()
tweet_id = resp.json()["data"]["id"]
发布一个帖子串
python
def post_thread(oauth, tweets: list[str]) -> list[str]:
    ids = []
    reply_to = None
    for text in tweets:
        payload = {"text": text}
        if reply_to:
            payload["reply"] = {"in_reply_to_tweet_id": reply_to}
        resp = oauth.post("https://api.x.com/2/tweets", json=payload)
        tweet_id = resp.json()["data"]["id"]
        ids.append(tweet_id)
        reply_to = tweet_id
    return ids
读取用户时间线
python
resp = requests.get(
    f"https://api.x.com/2/users/{user_id}/tweets",
    headers=headers,
    params={
        "max_results": 10,
        "tweet.fields": "created_at,public_metrics",
    }
)
搜索推文
python
resp = requests.get(
    "https://api.x.com/2/tweets/search/recent",
    headers=headers,
    params={
        "query": "from:affaanmustafa -is:retweet",
        "max_results": 10,
        "tweet.fields": "public_metrics,created_at",
    }
)
通过用户名获取用户
python
resp = requests.get(
    "https://api.x.com/2/users/by/username/affaanmustafa",
    headers=headers,
    params={"user.fields": "public_metrics,description,created_at"}
)
上传媒体并发布
python
# Media upload uses v1.1 endpoint

# Step 1: Upload media
media_resp = oauth.post(
    "https://upload.twitter.com/1.1/media/upload.json",
    files={"media": open("image.png", "rb")}
)
media_id = media_resp.json()["media_id_string"]

# Step 2: Post with media
resp = oauth.post(
    "https://api.x.com/2/tweets",
    json={"text": "Check this out", "media": {"media_ids": [media_id]}}
)

速率限制

X API 的速率限制因端点、认证方法和账户等级而异,并且会随时间变化。请始终:

  • 在硬编码假设之前,查看当前的 X 开发者文档
  • 在运行时读取 x-rate-limit-remaining 和 x-rate-limit-reset 头部信息
  • 自动退避,而不是依赖代码中的静态表格
python
import time

remaining = int(resp.headers.get("x-rate-limit-remaining", 0))
if remaining < 5:
    reset = int(resp.headers.get("x-rate-limit-reset", 0))
    wait = max(0, reset - int(time.time()))
    print(f"Rate limit approaching. Resets in {wait}s")

错误处理

python
resp = oauth.post("https://api.x.com/2/tweets", json={"text": content})
if resp.status_code == 201:
    return resp.json()["data"]["id"]
elif resp.status_code == 429:
    reset = int(resp.headers["x-rate-limit-reset"])
    raise Exception(f"Rate limited. Resets at {reset}")
elif resp.status_code == 403:
    raise Exception(f"Forbidden: {resp.json().get('detail', 'check permissions')}")
else:
    raise Exception(f"X API error {resp.status_code}: {resp.text}")

安全性

  • 切勿硬编码令牌。 使用环境变量或 .env 文件。
  • 切勿提交 .env 文件。 将其添加到 .gitignore。
  • 如果令牌暴露,请轮换令牌。 在 developer.x.com 重新生成。
  • 当不需要写权限时,使用只读令牌。
  • 安全存储 OAuth 密钥 — 不要存储在源代码或日志中。

与内容引擎集成

使用 content-engine 技能生成平台原生内容,然后通过 X API 发布:

  1. 使用内容引擎生成内容(X 平台格式)
  2. 验证长度(单条推文 280 字符)
  3. 使用上述模式通过 X API 发布
  4. 通过 public_metrics 跟踪参与度

相关技能

  • content-engine — 为 X 生成平台原生内容
  • crosspost — 在 X、LinkedIn 和其他平台分发内容

© affaan-m, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in docs/zh-CN/skills/x-api of affaan-m/ECC.

Open the folder on GitHubat commit ef648e0

Used in 2 other repositories

We found 2 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 2 other GitHub owners. This page covers the copy in affaan-m/ECC, which our catalogue first saw on October 9, 2026.

Compare with similar skills

X API next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

X API compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
X API this skillaffaan-m/ECC276k2 repos~1.1kAutomated safety check: NotesMIT
Twitterapi IokaitoInfra/twitterapi-io450—~3.1kAutomated safety check: PassMIT
Xquik MCPXquik-dev/x-twitter-scraper2101 repos~997Automated safety check: PassMIT
Socialite Developmenthexlet-volunteers/hexlet-sicp1145 repos~1.2kAutomated safety check: PassMIT
Unifapiunifapi-agent/agents589—~741Automated safety check: PassMIT
X Openapi Skillholon-run/uxc116—~1.3kAutomated safety check: PassMIT

Similar skills

  • Twitterapi Io

    kaitoInfra/twitterapi-io

    Official skill for twitterapi.io — query Twitter/X data (tweets, profiles, followers, advanced search, trends, spaces, communities, lists) and perform authenticated actions (post, reply, like…

    450 GitHub stars~3.1k tokensUpdated 4 mo ago
    Backend & APIsAuto-check passed
  • Xquik MCP

    Xquik-dev/x-twitter-scraper

    Connect, verify, and troubleshoot Xquik's remote MCP server.

    210 GitHub starsUsed in 1 repo~997 tokens
    Backend & APIsAuto-check passed
  • Socialite Development

    hexlet-volunteers/hexlet-sicp

    Manages OAuth social authentication with Laravel Socialite. An agent skill from hexlet-volunteers/hexlet-sicp.

    114 GitHub starsUsed in 5 repos~1.2k tokens
    Backend & APIsAuto-check passed
  • Unifapi

    unifapi-agent/agents

    A skill your agent uses when working with UnifAPI public-data APIs or the UnifAPI MCP server: connecting OAuth MCP clients, discovering operations, calling social/search/scrape/news APIs…

    589 GitHub stars~741 tokensUpdated 1 mo ago
    Backend & APIsAuto-check passed
  • X Openapi Skill

    holon-run/uxc

    Operate X API v2 through UXC with the official OpenAPI schema, OAuth2 PKCE user-context auth, app-only bearer guidance, and read-first guardrails for timeline/bookmark/post workflows.

    116 GitHub stars~1.3k tokensUpdated 24 days ago
    Backend & APIsAuto-check passed
  • X API

    sundial-org/awesome-openclaw-skills

    Post to X (Twitter) using the official API with OAuth 1.0a. An agent skill from sundial-org/awesome-openclaw-skills.

    663 GitHub stars~598 tokensUpdated 7 mo ago
    Backend & APIsAuto-check passed

More from affaan-m/ECC

All 673 skills in this repo
  • Skill Stocktake

    affaan-m/ECC

    Audits your installed Claude skills and commands for quality, with a quick mode for recently changed skills and a full mode that evaluates all of them through subagents.

    276k GitHub starsUsed in 5 repos~1.9k tokens
    Auto-check passed
  • Ingests, indexes, searches, edits and monitors video, audio and live streams through the VideoDB Python SDK, returning stream links, clips and timestamps.

    276k GitHub starsUsed in 3 repos~3.5k tokens
    Auto-check: notes
  • Rules Distillation

    affaan-m/ECC

    Scans installed skills for principles that recur across them and proposes rule-file changes: append, revise, add a section, create a file or leave as covered.

    276k GitHub starsUsed in 2 repos~2.3k tokens
    Auto-check passed
  • Builds DRAFT counterparty agreements from one markdown template and a small JSON spec per party, with clauses picked by the party's role.

    276k GitHub stars~2.9k tokensUpdated 4 days ago
    Auto-check passed
  • Measures whether agents actually follow a skill, rule or agent definition by generating scenarios at three strictness levels and scoring tool-call traces.

    276k GitHub starsUsed in 1 repo~623 tokens
    Auto-check passed
  • Instinct-based learning system that observes sessions via hooks, creates atomic instincts with confidence scoring, and evolves them into skills/commands/agents.

    276k GitHub stars~3.5k tokensUpdated 4 days ago
    Auto-check passed

Works with

Categories

Questions about X API

What does X API do?

X/Twitter API集成,用于发布推文、线程、读取时间线、搜索和分析。涵盖OAuth认证模式、速率限制和平台原生内容发布。当用户希望以编程方式与X交互时使用。. X API is an agent skill from affaan-m/ECC.

When should I use X API?

X API fits situations like: tasks that involve OAuth and OpenID Connect.

How do I install X API in Claude Code?

Run `npx skills add affaan-m/ECC --skill x-api -a claude-code`. Or copy the skill folder (docs/zh-CN/skills/x-api in affaan-m/ECC) into .claude/skills/x-api in your project. Claude Code loads it when a task matches its description.

How do I install X API in Codex?

Run `npx skills add affaan-m/ECC --skill x-api -a codex`. Or copy the skill folder (docs/zh-CN/skills/x-api in affaan-m/ECC) into .agents/skills/x-api in your project. Codex loads it when a task matches its description.

Can I use X API in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add affaan-m/ECC --skill x-api -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/x-api, .gemini/skills/x-api, .github/skills/x-api and .opencode/skills/x-api in your project.

What does X API need to run?

Going by SKILL.md and its folder, X API needs credentials named X_BEARER_TOKEN, X_API_KEY, X_API_SECRET and X_ACCESS_TOKEN. Our summary lists: Python 3; A credential in X_BEARER_TOKEN; A credential in X_API_KEY.

Does X API access the network?

SKILL.md names 2 domains. In commands or code: api.x.com and upload.twitter.com; the agent is likely to contact these when it follows the instructions. This is read from the text; nothing was executed.

Is X API safe to install?

Our automated static check of SKILL.md found notes only (mentions a .env file), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does X API use?

X API is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does X API use?

About 1.1k tokens (SKILL.md is roughly 4.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to X API?

Skills that share tags, products or a category with X API: Twitterapi Io (kaitoInfra/twitterapi-io, 450 stars), Xquik MCP (Xquik-dev/x-twitter-scraper, 210 stars), Socialite Development (hexlet-volunteers/hexlet-sicp, 114 stars) and Unifapi (unifapi-agent/agents, 589 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains X API?

affaan-m (a GitHub user) maintains it in affaan-m/ECC, which has 275,546 GitHub stars. The repository holds 673 skills in this directory. The repository was last updated on October 5, 2026.

Source: affaan-m/ECC on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.