当前位置: 首页 > Skill >

X Analytics CLI

X Analytics CLI

1.0.0 2026.11.11 浏览:965
获取Skill文件查看使用说明
作者:苏辰许可证:
本文目录展开

X Analytics CLI Skill

You have access to x-analytics-cli, a read-only CLI for the X API v2. Use it to search recent tweets, count tweet volumes over time, look up users and tweets by ID, and retrieve the authenticated user's timeline. All requests use OAuth 1.0a signing.

Quick start

# Check if the CLI is available
x-analytics-cli --help

# Get the authenticated user's profile
x-analytics-cli me

# Search recent tweets
x-analytics-cli search "OpenAI"

If the CLI is not installed, install it:

npm install -g x-analytics-cli

Authentication

The CLI requires four OAuth 1.0a credentials: API Key, API Secret, Access Token, and Access Token Secret. Credentials are resolved in this order:

  1. --credentials <path> flag (per-command)
  2. Environment variables: X_API_KEY, X_API_SECRET, X_ACCESS_TOKEN, X_ACCESS_TOKEN_SECRET
  3. Auto-detected file: ~/.config/x-analytics-cli/credentials.json

The credentials JSON file must contain these four fields:

{
  "api_key": "...",
  "api_secret": "...",
  "access_token": "...",
  "access_token_secret": "..."
}

API access tiers affect which commands are available:

  • Free tier -- authenticated user lookup (me)
  • Basic or higher -- tweet lookup (tweet, tweets), user lookup (user), search (search), tweet counts (tweet-counts), timelines (timeline)

Before running any command, verify credentials are configured by running x-analytics-cli me. If it fails with a credentials error, ask the user to set up authentication.

Output format

All commands output pretty-printed JSON by default. Use --format compact for single-line JSON (useful for piping). The only valid format values are json (default) and compact.

Errors are written to stderr as JSON with an error field and a non-zero exit code, e.g. {"error": "Unauthorized - Invalid or expired token"}.

The response shape follows the X API v2 convention: data (primary results), includes (expanded objects), and meta (pagination info). Not all fields are present in every response.

Commands reference

User lookup

me

Get the authenticated user's profile.

x-analytics-cli me
x-analytics-cli me --user-fields public_metrics,description,created_at
x-analytics-cli me --expansions pinned_tweet_id --tweet-fields created_at,public_metrics

Options:

  • --user-fields <fields> -- user fields to include
  • --expansions <expansions> -- expansions to include
  • --tweet-fields <fields> -- tweet fields to include (useful with expansions)

user

Get a user by username or numeric ID. Accepts usernames with or without the leading @. Numeric IDs are auto-detected and routed to the ID-based endpoint.

x-analytics-cli user elonmusk
x-analytics-cli user @elonmusk
x-analytics-cli user 44196397
x-analytics-cli user elonmusk --user-fields public_metrics,description,created_at
x-analytics-cli user elonmusk --expansions pinned_tweet_id --tweet-fields text

Options:

  • --user-fields <fields> -- user fields to include
  • --expansions <expansions> -- expansions to include
  • --tweet-fields <fields> -- tweet fields to include (useful with expansions)

Tweet lookup

tweet

Get a single tweet by ID.

x-analytics-cli tweet 1234567890
x-analytics-cli tweet 1234567890 --tweet-fields public_metrics,created_at,author_id
x-analytics-cli tweet 1234567890 --expansions author_id --user-fields username,name

Options:

  • --tweet-fields <fields> -- tweet fields to include
  • --expansions <expansions> -- expansions to include
  • --user-fields <fields> -- user fields to include
  • --media-fields <fields> -- media fields to include
  • --place-fields <fields> -- place fields to include
  • --poll-fields <fields> -- poll fields to include

tweets

Get multiple tweets by IDs (comma-separated).

x-analytics-cli tweets 1234567890,9876543210
x-analytics-cli tweets 1234567890,9876543210 --tweet-fields public_metrics,created_at
x-analytics-cli tweets 1234567890,9876543210 --expansions author_id --user-fields username,name

Options:

  • --tweet-fields <fields> -- tweet fields to include
  • --expansions <expansions> -- expansions to include
  • --user-fields <fields> -- user fields to include
  • --media-fields <fields> -- media fields to include
  • --place-fields <fields> -- place fields to include
  • --poll-fields <fields> -- poll fields to include

Search

search

Search recent tweets (last 7 days). Requires Basic API access or higher.

x-analytics-cli search "from:elonmusk"
x-analytics-cli search "OpenAI" --max-results 50 --sort-order relevancy
x-analytics-cli search "#AI" --start-time 2026-03-10T00:00:00Z --end-time 2026-03-17T00:00:00Z
x-analytics-cli search "lang:en bitcoin" --tweet-fields public_metrics,created_at,author_id --expansions author_id --user-fields username

Options:

  • --max-results <n> -- max results, 10-100
  • --start-time <time> -- ISO 8601 start time
  • --end-time <time> -- ISO 8601 end time
  • --sort-order <order> -- recency or relevancy
  • --next-token <token> -- pagination token from meta.next_token in the response
  • --tweet-fields <fields> -- tweet fields to include
  • --expansions <expansions> -- expansions to include
  • --user-fields <fields> -- user fields to include
  • --media-fields <fields> -- media fields to include
  • --place-fields <fields> -- place fields to include
  • --poll-fields <fields> -- poll fields to include

Supports the full X API v2 search query syntax: from:, to:, is:retweet, has:media, lang:, hashtags, mentions, boolean operators (OR, -), and more.

tweet-counts

Get tweet counts for a search query over time (last 7 days). Requires Basic API access or higher.

x-analytics-cli tweet-counts "OpenAI"
x-analytics-cli tweet-counts "#AI" --granularity hour
x-analytics-cli tweet-counts "from:elonmusk" --granularity day --start-time 2026-03-01T00:00:00Z
x-analytics-cli tweet-counts "bitcoin OR ethereum" --granularity minute --start-time 2026-03-18T00:00:00Z --end-time 2026-03-18T01:00:00Z

Options:

  • --granularity <g> -- minute, hour, or day (default: day)
  • --start-time <time> -- ISO 8601 start time
  • --end-time <time> -- ISO 8601 end time
  • --next-token <token> -- pagination token from meta.next_token in the response

Returns an array of time-bucketed counts in data, plus meta.total_tweet_count for the total across all buckets.

Timeline

timeline

Get tweets posted by the authenticated user. Internally calls /users/me first to resolve the user ID, then fetches the timeline.

x-analytics-cli timeline
x-analytics-cli timeline --max-results 50
x-analytics-cli timeline --exclude retweets,replies
x-analytics-cli timeline --tweet-fields public_metrics,created_at --start-time 2026-03-01T00:00:00Z
x-analytics-cli timeline --max-results 20 --expansions author_id --user-fields username

Options:

  • --max-results <n> -- max results, 1-100
  • --start-time <time> -- ISO 8601 start time
  • --end-time <time> -- ISO 8601 end time
  • --exclude <types> -- exclude types: retweets, replies (comma-separated)
  • --next-token <token> -- pagination token from meta.next_token in the response
  • --tweet-fields <fields> -- tweet fields to include
  • --expansions <expansions> -- expansions to include
  • --user-fields <fields> -- user fields to include
  • --media-fields <fields> -- media fields to include
  • --place-fields <fields> -- place fields to include
  • --poll-fields <fields> -- poll fields to include

Common field values

tweet-fields

attachments, author_id, context_annotations, conversation_id, created_at, edit_controls, edit_history_tweet_ids, entities, geo, id, in_reply_to_user_id, lang, public_metrics, possibly_sensitive, referenced_tweets, reply_settings, source, text, withheld

The public_metrics object contains: retweet_count, reply_count, like_count, quote_count, bookmark_count, impression_count.

user-fields

created_at, description, entities, id, location, most_recent_tweet_id, name, pinned_tweet_id, profile_image_url, protected, public_metrics, url, username, verified, verified_type, withheld

The public_metrics object contains: followers_count, following_count, tweet_count, listed_count.

media-fields

duration_ms, height, media_key, preview_image_url, public_metrics, type, url, width, alt_text, variants

expansions (for tweets)

author_id, referenced_tweets.id, in_reply_to_user_id, attachments.media_keys, attachments.poll_ids, geo.place_id, entities.mentions.username, referenced_tweets.id.author_id, edit_history_tweet_ids

expansions (for users)

pinned_tweet_id

Pagination

The search, tweet-counts, and timeline commands support pagination via --next-token. When a response includes meta.next_token, pass that value to the next call to fetch the next page. The me, user, tweet, and tweets commands do not paginate.

Workflow guidance

When the user asks about a user's profile or stats

  1. Run x-analytics-cli user <username> --user-fields public_metrics,description,created_at to get their profile and metrics
  2. Present follower counts, tweet count, and account creation date

When the user asks to search for tweets on a topic

  1. Run x-analytics-cli search "<query>" --max-results 50 --tweet-fields public_metrics,created_at,author_id --expansions author_id --user-fields username
  2. Adjust --sort-order relevancy if the user wants the most relevant results rather than the most recent
  3. Use --next-token to paginate through more results if needed

When the user asks about tweet volume or trends

  1. Run x-analytics-cli tweet-counts "<query>" --granularity hour to see volume over time
  2. Use --granularity minute for fine-grained analysis or --granularity day for a broader view
  3. Narrow with --start-time and --end-time for a specific window
  4. Compare multiple queries by running tweet-counts for each term

When the user asks about a specific tweet

  1. Run x-analytics-cli tweet <id> --tweet-fields public_metrics,created_at,author_id --expansions author_id --user-fields username to get the tweet with engagement metrics and author info
  2. For multiple tweets, use x-analytics-cli tweets <id1>,<id2> with the same fields

When the user asks about their own tweets

  1. Run x-analytics-cli timeline --max-results 50 --tweet-fields public_metrics,created_at to get recent tweets with engagement
  2. Use --exclude retweets,replies to focus on original tweets only
  3. Use --start-time and --end-time to narrow to a specific date range

When the user asks for a comprehensive analysis

  1. Start with x-analytics-cli me --user-fields public_metrics to get the user's own stats
  2. Use timeline with --tweet-fields public_metrics to analyze engagement on their tweets
  3. Use search "from:<username>" for a broader view of their recent output
  4. Use tweet-counts "from:<username>" --granularity day to see their posting frequency

Error handling

  • "No credentials found" -- ask the user to set up authentication via credentials file, environment variables, or --credentials flag
  • "Unauthorized" -- the access token is invalid or expired; ask the user to regenerate tokens in the X Developer Portal
  • "Forbidden" / 403 -- the API access tier may not support the endpoint (e.g., search requires Basic tier)
  • Empty data -- the query returned no results; check the search query syntax, date range, or whether the user/tweet exists
  • Rate limit errors -- the X API has per-endpoint rate limits; wait and retry, or reduce request frequency

API documentation references

  • x-analytics-cli documentation
  • X API v2 overview
  • Tweet Lookup
  • User Lookup
  • Recent Search
  • Tweet Counts
  • Timelines
  • X API v2 fields and expansions
  • Search query syntax

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,033
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,018
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,016
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,012
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,012
Skill 文件
  • SKILL.md
    • X Analytics CLI Skill
    • Quick start
    • Authentication
    • Output format
    • Commands reference
      • User lookup
        • me
        • user
      • Tweet lookup
        • tweet
        • tweets
      • Search
        • search
        • tweet-counts
      • Timeline
        • timeline
      • Common field values
        • tweet-fields
        • user-fields
        • media-fields
        • expansions (for tweets)
        • expansions (for users)
      • Pagination
    • Workflow guidance
      • When the user asks about a user's profile or stats
      • When the user asks to search for tweets on a topic
      • When the user asks about tweet volume or trends
      • When the user asks about a specific tweet
      • When the user asks about their own tweets
      • When the user asks for a comprehensive analysis
    • Error handling
    • API documentation references
  • 项目或源文件

相关 Skill

更多
X Tweet By Conversation X Tweet By Conversation Collects every tweet in an X (Twitter) conversation thread given a conversation id (root tweet id) — the focal tweet plus all replies, sub-replies, and quote chains — and returns normalized per-tweet data with text, author, engagement counts, media, hashtags, mentions, in_reply_to mapping, and curso
Fxtwitter Extract Fxtwitter Extract 使用 FxTwitter API 提取 X (Twitter) 文章内容。支持提取推文、线程、用户资料,包括文本、图片、视频、投票等。无需 API Key。
xAI Grok Search xAI Grok Search 使用 xAI Grok API 搜索网页和 X (Twitter),支持实时访问、引用和图像理解。
AI Trend Hunter Pro AI Trend Hunter Pro A high-performance automation agent that turns global trends into viral social media posts for X (Twitter), Xiaohongshu, and LinkedIn — built on the exact sc...
AdaptlyPost AdaptlyPost 使用 AdaptlyPost API 在 Instagram、X (Twitter)、Bluesky、TikTok、Threads、LinkedIn、Facebook、Pinterest 和 YouTube 上安排和管理社交媒体帖子。适用于用户想要安排社交媒体帖子、管理社交媒体内容、上传媒体文件进行社交发布、列出已连接的社交媒体账户等场景。