x-api

GitHub

提供X(Twitter) API只读访问,支持搜索推文、获取用户资料及回复线程。用于金融舆情分析、新闻追踪和事件研究,需配置Bearer Token认证。

plugins/alternative_data/skills/x-api/SKILL.md ginlix-ai/LangAlpha

Trigger Scenarios

查询X/Twitter内容 分析特定话题或股票代码的公众情绪 检索历史推文或事件反应 读取推文回复线程

Install

npx skills add ginlix-ai/LangAlpha --skill x-api -g -y
More Options

Non-standard path

npx skills add https://github.com/ginlix-ai/LangAlpha/tree/main/plugins/alternative_data/skills/x-api -g -y

Use without installing

npx skills use ginlix-ai/LangAlpha@x-api

指定 Agent (Claude Code)

npx skills add ginlix-ai/LangAlpha --skill x-api -a claude-code -g -y

安装 repo 全部 skill

npx skills add ginlix-ai/LangAlpha --all -g -y

预览 repo 内 skill

npx skills add ginlix-ai/LangAlpha --list

SKILL.md

Frontmatter
{
    "name": "x-api",
    "description": "Search X (Twitter) posts, pull user profiles, fetch specific tweets, and read reply threads for sentiment, news, and event research. Triggers on 'X', 'Twitter', 'tweets about', 'sentiment on', 'what are people saying about', 'historical tweets', or any request to read public X content."
}

X (Twitter) API

Read-only access to X content via five MCP tools. Use for sentiment on tickers, exec announcements, launches, event tracking, and qualitative research alongside SEC/market data.

Not for single-post URL lookups. If the user hands you a specific X post URL and just wants its text or context, use web_fetch on the URL — no vault, no auth, no rate limit. Reach for this skill when the task is search, aggregation, or thread traversal.

Auth

Every tool requires a bearer_token. Read it once per code block from the vault:

from vault import get
token = get("X_BEARER_TOKEN")

If token is None or empty, the user hasn't added it yet. For the setup walkthrough and per-error fixes, see TROUBLESHOOTING.md.

Tools at a glance

The primary use case is search — the first two tools are what you'll reach for most.

Tool Use for Page size Notes
search_posts Posts from the last ~7 days default 10, max 100 Default choice. Query ≤512 chars.
search_all_posts Posts older than 7 days (back to 2006) default 10, max 500 Paid-tier X plan only. Query ≤1024 chars.
get_conversation Reply thread to a root tweet default 50, max 100 Uses recent search — thread must be ≤7 days old. Root tweet not included.
get_user_by_username A user profile + metrics — Handle without @, ≤15 chars.
get_tweet_by_id Hydrate a single post (mainly to find its conversation_id before get_conversation) — For a one-off URL the user already has, prefer web_fetch.

Examples

Recent sentiment on a ticker

res = search_posts(
    query="$NVDA -is:retweet lang:en",
    bearer_token=token,
    max_results=100,
)
posts = res["posts"]
posts.sort(key=lambda p: p["public_metrics"].get("impression_count", 0), reverse=True)
for p in posts[:10]:
    print(p["author"]["username"], p["public_metrics"].get("like_count"), p["text"][:140])

Historical reaction to a past event

res = search_all_posts(
    query="$TSLA earnings -is:retweet lang:en",
    bearer_token=token,
    max_results=500,
    start_time="2020-03-13T00:00:00Z",
    end_time="2020-03-20T00:00:00Z",
)

Full thread on a specific tweet

root = get_tweet_by_id(tweet_id="1700000000000000001", bearer_token=token)
thread = get_conversation(
    conversation_id=root["post"]["conversation_id"],
    bearer_token=token,
    max_results=100,
)
all_posts = [root["post"], *thread["posts"]]

Paginate through a large result

posts, next_tok = [], None
while len(posts) < 500:
    res = search_posts(
        query="from:FedSpeakers",
        bearer_token=token,
        max_results=100,
        next_token=next_tok,
    )
    if "error" in res:
        break
    posts.extend(res["posts"])
    next_tok = res.get("next_token")
    if not next_tok:
        break

Post shape

Each post: id, text, created_at, lang, conversation_id, author_id, edit_history_tweet_ids, public_metrics (retweet/reply/like/quote/bookmark/impression counts), author — which is {id, username, name, verified}, {id, unresolved: true} for suspended/deleted users, or None if the tweet has no author_id.

Full per-tool response schemas (including user shape and error variants): reference.md.

Query syntax

$TSLA (cashtag), #hashtag, from:elonmusk, to:@SEC_News, -is:retweet, is:verified, has:links, has:media, lang:en, "exact phrase", parentheses + OR for alternation. Full list: https://docs.x.com/x-api/posts/search/introduction.

Errors

Every tool returns {"error": "...", ...} on failure — they never raise. Always check for error before accessing posts / user / post. For the per-error playbook (including setup fixes and tier gotchas), read TROUBLESHOOTING.md.

Do / Don't

  • Do read token = get("X_BEARER_TOKEN") once and reuse it across calls.
  • Do cross-reference with get_daily_prices and get_sec_filing when investigating price moves or disclosures.
  • Don't hardcode tokens. Ever.
  • Don't cache next_token across sessions — cursors can expire.
  • Don't assume every author is resolved — check for {unresolved: true} before reading username.

Related

  • get_daily_prices — cross-reference X sentiment with price action
  • get_sec_filing — pair chatter with official disclosures
  • scrape scrape_page / scrape_pages — fallback for public pages when the API is blocked
  • web_search — broader news search that also indexes X posts

Version History

  • 8e0dce9 Current 2026-10-18 20:16

    将MCP服务器安装与Vault密钥管理从工作区本地迁移至用户全局级别,修复了密钥同步、状态统计及沙箱环境中的权限与数据一致性问题。

  • c2ebaa6 2026-08-27 11:25

Same Skill Collection

plugins/alternative_data/skills/web-scraping/SKILL.md
plugins/langalpha_deliverables/skills/chart-annotation/SKILL.md
plugins/langalpha_deliverables/skills/docx/SKILL.md
plugins/langalpha_deliverables/skills/html-report/SKILL.md
plugins/langalpha_deliverables/skills/inline-widget/SKILL.md
plugins/langalpha_deliverables/skills/interactive-dashboard/SKILL.md
plugins/langalpha_deliverables/skills/pdf/SKILL.md
plugins/langalpha_deliverables/skills/pptx/SKILL.md
plugins/langalpha_deliverables/skills/ui-design/SKILL.md
plugins/langalpha_deliverables/skills/xlsx/SKILL.md
plugins/langalpha_research/skills/3-statements/SKILL.md
plugins/langalpha_research/skills/catalyst-calendar/SKILL.md
plugins/langalpha_research/skills/check-deck/SKILL.md
plugins/langalpha_research/skills/check-model/SKILL.md
plugins/langalpha_research/skills/company-profile/SKILL.md
plugins/langalpha_research/skills/competitive-analysis/SKILL.md
plugins/langalpha_research/skills/comps-analysis/SKILL.md
plugins/langalpha_research/skills/dcf-model/SKILL.md
plugins/langalpha_research/skills/earnings-analysis/SKILL.md
plugins/langalpha_research/skills/earnings-preview/SKILL.md
plugins/langalpha_research/skills/idea-generation/SKILL.md
plugins/langalpha_research/skills/impact-analysis/SKILL.md
plugins/langalpha_research/skills/initiating-coverage/SKILL.md
plugins/langalpha_research/skills/market-watch/SKILL.md
plugins/langalpha_research/skills/model-update/SKILL.md
plugins/langalpha_research/skills/morning-note/SKILL.md
plugins/langalpha_research/skills/research-conventions/SKILL.md
plugins/langalpha_research/skills/sector-overview/SKILL.md
plugins/langalpha_research/skills/thesis-tracker/SKILL.md
plugins/langalpha_research/skills/trade-pitch/SKILL.md
plugins/langalpha_service/skills/automation/SKILL.md
plugins/langalpha_service/skills/langalpha-doc/SKILL.md
plugins/langalpha_service/skills/onboarding/SKILL.md
plugins/langalpha_service/skills/run-workflow/SKILL.md
plugins/langalpha_service/skills/secretary/SKILL.md
plugins/langalpha_service/skills/self-improve/SKILL.md
plugins/langalpha_service/skills/user-profile/SKILL.md
skills/3-statements/SKILL.md
skills/automation/SKILL.md
skills/catalyst-calendar/SKILL.md
skills/chart-annotation/SKILL.md
skills/check-deck/SKILL.md
skills/check-model/SKILL.md
skills/competitive-analysis/SKILL.md
skills/comps-analysis/SKILL.md
skills/dcf-model/SKILL.md
skills/earnings-analysis/SKILL.md
skills/earnings-preview/SKILL.md
skills/html-report/SKILL.md

Metadata

Files
0
Version
8e0dce9
Hash
4c3966ed
Indexed
2026-08-27 11:25

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-19 02:58
浙ICP备14020137号-1