{"_id":"x-analytics-cli","_rev":"4-109a69c4445c20233b6eb8d307c6bbe1","name":"x-analytics-cli","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"x-analytics-cli","version":"1.0.0","keywords":["x-analytics","twitter","analytics","cli","ai-agent","api"],"author":{"name":"Benn Huang","email":"tohuangbin@gmail.com"},"license":"Apache-2.0","_id":"x-analytics-cli@1.0.0","maintainers":[{"name":"bennhuang","email":"tohuangbin@gmail.com"}],"homepage":"https://github.com/Bin-Huang/x-analytics-cli#readme","bugs":{"url":"https://github.com/Bin-Huang/x-analytics-cli/issues"},"bin":{"x-analytics-cli":"dist/index.js"},"dist":{"shasum":"820e985a63653dcbd6bccba2050cbf34399b3fbe","tarball":"https://registry.npmjs.org/x-analytics-cli/-/x-analytics-cli-1.0.0.tgz","fileCount":12,"integrity":"sha512-ybTy/Xmvm3RFq1YHYjdCrcvZSTzYMpv3ASwJdIVcPzm56nu6urId1oT34eJlz0kDyIB1FTAkKd9BHZIgk2g4lw==","signatures":[{"sig":"MEUCIQD7HyczHTyve/R4hKNI89GVZjb3cfUoouJ3CTZxYCIgLwIgZQfBXNCqu1yqtoZlnhpGiKCyqcBuKbiibIXvhi+2Qvo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35850},"type":"module","_from":"file:x-analytics-cli-1.0.0.tgz","engines":{"node":">=18"},"scripts":{"build":"tsc"},"_npmUser":{"name":"bennhuang","email":"tohuangbin@gmail.com"},"_resolved":"/private/var/folders/rv/s95dj9fx5r96n8nt3c4j4r040000gn/T/25a690fca1e82bc2286cdd46f9aec5b4/x-analytics-cli-1.0.0.tgz","_integrity":"sha512-ybTy/Xmvm3RFq1YHYjdCrcvZSTzYMpv3ASwJdIVcPzm56nu6urId1oT34eJlz0kDyIB1FTAkKd9BHZIgk2g4lw==","repository":{"url":"git+https://github.com/Bin-Huang/x-analytics-cli.git","type":"git"},"_npmVersion":"10.8.2","description":"X Analytics CLI for AI agents","directories":{},"_nodeVersion":"20.19.0","dependencies":{"commander":"^14.0.3"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.5.0"},"_npmOperationalInternal":{"tmp":"tmp/x-analytics-cli_1.0.0_1773740873746_0.36416640116520593","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"x-analytics-cli","version":"1.0.1","keywords":["x-analytics","twitter","analytics","cli","ai-agent","api"],"author":{"name":"Benn Huang","email":"tohuangbin@gmail.com"},"license":"Apache-2.0","_id":"x-analytics-cli@1.0.1","maintainers":[{"name":"bennhuang","email":"tohuangbin@gmail.com"}],"homepage":"https://github.com/Bin-Huang/x-analytics-cli#readme","bugs":{"url":"https://github.com/Bin-Huang/x-analytics-cli/issues"},"bin":{"x-analytics-cli":"dist/index.js"},"dist":{"shasum":"bb527bc09f78dcd6a00b7ef5d639529e15fe4ad9","tarball":"https://registry.npmjs.org/x-analytics-cli/-/x-analytics-cli-1.0.1.tgz","fileCount":12,"integrity":"sha512-zY4OJD0I5FxzNDAy9iZC0J3nRHc8IldPxoSkyI4jAIgLEW0pEGOp6bKh/QZ4NShdOhQfCbES38YsnP3aCrp3Iw==","signatures":[{"sig":"MEQCIAufHCj93K4rPCCLFx+odaiHL+YVKrDBc5mvNHskXgDXAiBRNM8JfLNaeu3oHKJZLEngZhUeBWAZ8kZv96eXEEtkVg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":36142},"type":"module","_from":"file:x-analytics-cli-1.0.1.tgz","engines":{"node":">=18"},"scripts":{"build":"tsc"},"_npmUser":{"name":"bennhuang","email":"tohuangbin@gmail.com"},"_resolved":"/private/var/folders/rv/s95dj9fx5r96n8nt3c4j4r040000gn/T/0dceb52cf10266800f58dabfdb9d5e89/x-analytics-cli-1.0.1.tgz","_integrity":"sha512-zY4OJD0I5FxzNDAy9iZC0J3nRHc8IldPxoSkyI4jAIgLEW0pEGOp6bKh/QZ4NShdOhQfCbES38YsnP3aCrp3Iw==","repository":{"url":"git+https://github.com/Bin-Huang/x-analytics-cli.git","type":"git"},"_npmVersion":"10.8.2","description":"X Analytics CLI for AI agents","directories":{},"_nodeVersion":"20.19.0","dependencies":{"commander":"^14.0.3"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.5.0"},"_npmOperationalInternal":{"tmp":"tmp/x-analytics-cli_1.0.1_1773744547799_0.1927027510699324","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"x-analytics-cli","version":"1.0.2","keywords":["x-analytics","twitter","analytics","cli","ai-agent","api"],"author":{"name":"Benn Huang","email":"tohuangbin@gmail.com"},"license":"Apache-2.0","_id":"x-analytics-cli@1.0.2","maintainers":[{"name":"bennhuang","email":"tohuangbin@gmail.com"}],"homepage":"https://github.com/Bin-Huang/x-analytics-cli#readme","bugs":{"url":"https://github.com/Bin-Huang/x-analytics-cli/issues"},"bin":{"x-analytics-cli":"dist/index.js"},"dist":{"shasum":"018041c5151510b611633abbcd75c31cbf8fb09f","tarball":"https://registry.npmjs.org/x-analytics-cli/-/x-analytics-cli-1.0.2.tgz","fileCount":12,"integrity":"sha512-0syV8zCGWVTVqOanPPrtkPthoyBEsBSb9h72YXJgB5zsq/wnuk4zWkdxkGS4e/VYPe23ljQKr8Y7rQbwn56+Fw==","signatures":[{"sig":"MEUCIQC3FjjJnIibY7wbU0cJyu9ascuRBCaGfNeTAakbXjf8VgIgId13nX//76XLfCzOO+RFL/dPI1jXFDsHk+fTAxSasKY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":36274},"type":"module","engines":{"node":">=18"},"gitHead":"b5f70e1b54020624a1b8496f7272e3c03c928cfe","scripts":{"build":"tsc","prepack":"pnpm build"},"_npmUser":{"name":"bennhuang","email":"tohuangbin@gmail.com"},"repository":{"url":"git+https://github.com/Bin-Huang/x-analytics-cli.git","type":"git"},"_npmVersion":"10.8.2","description":"X Analytics CLI for AI agents","directories":{},"_nodeVersion":"20.19.0","dependencies":{"commander":"^14.0.3"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.32.1","devDependencies":{"typescript":"^5.9.3","@types/node":"^25.5.0"},"_npmOperationalInternal":{"tmp":"tmp/x-analytics-cli_1.0.2_1773757567788_0.9742198307561725","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"x-analytics-cli","version":"1.0.3","description":"X Analytics CLI for AI agents","type":"module","bin":{"x-analytics-cli":"dist/index.js"},"scripts":{"build":"tsc","prepack":"pnpm build"},"author":{"name":"Benn Huang","email":"tohuangbin@gmail.com"},"license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/Bin-Huang/x-analytics-cli.git"},"engines":{"node":">=18"},"keywords":["x-analytics","twitter","analytics","cli","ai-agent","api"],"packageManager":"pnpm@10.32.1","devDependencies":{"@types/node":"^25.5.0","typescript":"^5.9.3"},"dependencies":{"commander":"^14.0.3"},"bugs":{"url":"https://github.com/Bin-Huang/x-analytics-cli/issues"},"homepage":"https://github.com/Bin-Huang/x-analytics-cli#readme","_id":"x-analytics-cli@1.0.3","gitHead":"5185fd43b57bdf2ab864de7f1e78f55c3c3df04e","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-0Ihl2tvU9eoEjCg3lcgu4aoVigq9LolZ4fY8bwVThHudzmCkEC0cXEmpnX76rVHA3Bw9O/J3xorluRPBn2wNIA==","shasum":"f6aa31b2f71388b3f28db735a40dd9a7eef1f8bc","tarball":"https://registry.npmjs.org/x-analytics-cli/-/x-analytics-cli-1.0.3.tgz","fileCount":12,"unpackedSize":36314,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCSPEWB11N2HuhpKvyJ5X5dJLEwprV7QHNrM+qORHPldAIhAN5BvqHTb8mXq/+1HdfpnxxpoUqiys7kVlttJPyogpY2"}]},"_npmUser":{"name":"bennhuang","email":"tohuangbin@gmail.com"},"directories":{},"maintainers":[{"name":"bennhuang","email":"tohuangbin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/x-analytics-cli_1.0.3_1773925352074_0.46794177930961967"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-17T09:47:53.669Z","modified":"2026-03-19T13:02:32.329Z","1.0.0":"2026-03-17T09:47:53.892Z","1.0.1":"2026-03-17T10:49:07.993Z","1.0.2":"2026-03-17T14:26:07.931Z","1.0.3":"2026-03-19T13:02:32.231Z"},"bugs":{"url":"https://github.com/Bin-Huang/x-analytics-cli/issues"},"author":{"name":"Benn Huang","email":"tohuangbin@gmail.com"},"license":"Apache-2.0","homepage":"https://github.com/Bin-Huang/x-analytics-cli#readme","keywords":["x-analytics","twitter","analytics","cli","ai-agent","api"],"repository":{"type":"git","url":"git+https://github.com/Bin-Huang/x-analytics-cli.git"},"description":"X Analytics CLI for AI agents","maintainers":[{"name":"bennhuang","email":"tohuangbin@gmail.com"}],"readme":"# x-analytics-cli\n\nX Analytics CLI for AI agents (and humans). Search recent tweets, count tweet volumes by time, pull user profiles and timelines, and more.\n\n**Works with:** OpenClaw, Claude Code, Cursor, Codex, and any agent that can run shell commands.\n\n## Installation\n\n```bash\nnpm install -g x-analytics-cli\n```\n\nOr run directly: `npx x-analytics-cli --help`\n\n## How it works\n\nBuilt on the official [X API v2](https://docs.x.com/x-api). Handles OAuth 1.0a signing natively with Node.js `crypto` (no external dependencies). Every command outputs structured JSON to stdout, ready for agents to parse without extra processing.\n\nCore endpoints covered:\n\n- **[Tweet Lookup](https://docs.x.com/x-api/posts/lookup)** -- get tweets by ID\n- **[User Lookup](https://docs.x.com/x-api/users/lookup)** -- get users by ID or username\n- **[Search](https://docs.x.com/x-api/posts/search)** -- search recent tweets\n- **[Tweet Counts](https://docs.x.com/x-api/posts/counts)** -- count tweets matching a query\n- **[Timelines](https://docs.x.com/x-api/posts/timelines)** -- get a user's tweet timeline\n\n## Setup\n\n### Step 1: Get X API access\n\n1. Go to the [X Developer Portal](https://developer.x.com/) and sign in.\n2. Create a project and app if you don't have one.\n3. Make sure your app has at least Basic access (Free tier only supports `GET /2/users/me`; Basic or higher is required for tweet lookup, user lookup, search, counts, and timelines).\n\n### Step 2: Get your API credentials\n\nIn the Developer Portal, under your app's \"Keys and Tokens\" page, obtain:\n\n- **API Key** (also called Consumer Key)\n- **API Secret** (also called Consumer Secret)\n- **Access Token**\n- **Access Token Secret**\n\n### Step 3: Place the credentials file\n\nChoose one of these options:\n\n```bash\n# Option A: Default path (recommended)\nmkdir -p ~/.config/x-analytics-cli\ncat > ~/.config/x-analytics-cli/credentials.json << EOF\n{\n  \"api_key\": \"YOUR_API_KEY\",\n  \"api_secret\": \"YOUR_API_SECRET\",\n  \"access_token\": \"YOUR_ACCESS_TOKEN\",\n  \"access_token_secret\": \"YOUR_ACCESS_TOKEN_SECRET\"\n}\nEOF\n\n# Option B: Environment variables\nexport X_API_KEY=your_api_key\nexport X_API_SECRET=your_api_secret\nexport X_ACCESS_TOKEN=your_access_token\nexport X_ACCESS_TOKEN_SECRET=your_access_token_secret\n\n# Option C: Pass per command\nx-analytics-cli --credentials /path/to/credentials.json me\n```\n\nCredentials are resolved in this order:\n1. `--credentials <path>` flag\n2. `X_API_KEY`, `X_API_SECRET`, `X_ACCESS_TOKEN`, `X_ACCESS_TOKEN_SECRET` env vars\n3. `~/.config/x-analytics-cli/credentials.json` (auto-detected)\n\n## Usage\n\nAll commands output pretty-printed JSON by default. Use `--format compact` for compact single-line JSON.\n\n### me\n\nGet the authenticated user's profile.\n\n```bash\nx-analytics-cli me\nx-analytics-cli me --user-fields public_metrics,description,created_at\n```\n\n### user\n\nGet a user by username or numeric ID.\n\n```bash\nx-analytics-cli user elonmusk\nx-analytics-cli user 44196397\nx-analytics-cli user elonmusk --user-fields public_metrics,description\n```\n\n### tweet\n\nGet a single tweet by ID.\n\n```bash\nx-analytics-cli tweet 1234567890\nx-analytics-cli tweet 1234567890 --tweet-fields public_metrics,created_at\n```\n\n### tweets\n\nGet multiple tweets by IDs (comma-separated).\n\n```bash\nx-analytics-cli tweets 1234567890,9876543210\nx-analytics-cli tweets 1234567890,9876543210 --tweet-fields public_metrics --expansions author_id --user-fields username\n```\n\n### search\n\nSearch recent tweets (last 7 days).\n\n```bash\nx-analytics-cli search \"from:elonmusk\"\nx-analytics-cli search \"OpenAI\" --max-results 50 --sort-order relevancy\nx-analytics-cli search \"#AI\" --start-time 2026-03-10T00:00:00Z --end-time 2026-03-17T00:00:00Z\n```\n\nOptions:\n- `--max-results <n>` -- 10-100 (default 10)\n- `--start-time <time>` -- ISO 8601 start time\n- `--end-time <time>` -- ISO 8601 end time\n- `--sort-order <order>` -- `recency` or `relevancy`\n- `--next-token <token>` -- pagination token\n- `--tweet-fields`, `--user-fields`, `--media-fields`, `--expansions` -- field selection\n\n### tweet-counts\n\nGet tweet counts for a search query (last 7 days).\n\n```bash\nx-analytics-cli tweet-counts \"OpenAI\"\nx-analytics-cli tweet-counts \"#AI\" --granularity hour\nx-analytics-cli tweet-counts \"from:elonmusk\" --granularity day --start-time 2026-03-01T00:00:00Z\n```\n\nOptions:\n- `--granularity <g>` -- `minute`, `hour`, or `day` (default `day`)\n- `--start-time <time>` -- ISO 8601 start time\n- `--end-time <time>` -- ISO 8601 end time\n- `--next-token <token>` -- pagination token\n\n### timeline\n\nGet tweets posted by the authenticated user.\n\n```bash\nx-analytics-cli timeline\nx-analytics-cli timeline --max-results 50 --exclude retweets,replies\nx-analytics-cli timeline --tweet-fields public_metrics,created_at --start-time 2026-03-01T00:00:00Z\n```\n\nOptions:\n- `--max-results <n>` -- 1-100\n- `--start-time <time>` -- ISO 8601 start time\n- `--end-time <time>` -- ISO 8601 end time\n- `--exclude <types>` -- `retweets`, `replies` (comma-separated)\n- `--next-token <token>` -- pagination token\n- `--tweet-fields`, `--user-fields`, `--media-fields`, `--expansions` -- field selection\n\n## Error output\n\nErrors are written to stderr as JSON with an `error` field and a non-zero exit code:\n\n```json\n{\"error\": \"Unauthorized - Invalid or expired token\"}\n```\n\n## API Reference\n\n- Official docs: https://docs.x.com/x-api\n\n## Related\n\n- [x-ads-cli](https://github.com/Bin-Huang/x-ads-cli) -- X Ads\n- [youtube-analytics-cli](https://github.com/Bin-Huang/youtube-analytics-cli) -- YouTube Analytics\n- [google-analytics-cli](https://github.com/Bin-Huang/google-analytics-cli) -- Google Analytics\n- [google-search-console-cli](https://github.com/Bin-Huang/google-search-console-cli) -- Google Search Console\n- [meta-ads-open-cli](https://github.com/Bin-Huang/meta-ads-open-cli) -- Meta Ads\n\n## License\n\nApache-2.0\n","readmeFilename":"README.md"}