home / skills / openclaw / skills / x-api

This skill enables posting to X via the official API with OAuth 1.0a, ensuring reliable tweets and authenticated content publication.

npx playbooks add skill openclaw/skills --skill x-api

Review the files below or copy the command above to add this skill to your agents.

Files (5)
SKILL.md
2.3 KB
---
name: x-api
description: Post to X (Twitter) using the official API with OAuth 1.0a. Use when you need to tweet, post updates, or publish content. Bypasses rate limits and bot detection that affect cookie-based approaches like bird CLI.
---

# x-api 🐦

Post to X using the official API (OAuth 1.0a).

## When to Use

- Posting tweets (cookie-based `bird tweet` gets blocked by bot detection)
- Official API access is needed for reliability

For **reading** (timeline, search, mentions), use `bird` CLI instead — it's free and works well for reads.

## Setup

### 1. Get API Credentials

1. Go to https://developer.x.com/en/portal/dashboard
2. Create a Project and App
3. Set App permissions to **Read and Write**
4. Get your keys from "Keys and tokens" tab:
   - API Key (Consumer Key)
   - API Key Secret (Consumer Secret)
   - Access Token
   - Access Token Secret

### 2. Configure Credentials

**Option A: Environment variables**
```bash
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-token-secret"
```

**Option B: Config file** at `~/.clawdbot/secrets/x-api.json`
```json
{
  "consumerKey": "your-api-key",
  "consumerSecret": "your-api-secret",
  "accessToken": "your-access-token",
  "accessTokenSecret": "your-access-token-secret"
}
```

### 3. Install Dependency

```bash
npm install -g twitter-api-v2
```

## Post a Tweet

```bash
x-post "Your tweet text here"
```

Or with full path:
```bash
node /path/to/skills/x-api/scripts/x-post.mjs "Your tweet text here"
```

Supports multi-line tweets:
```bash
x-post "Line one

Line two

Line three"
```

Returns the tweet URL on success.

## Limits

- Free tier: 1,500 posts/month (requires credits in X Developer Portal)
- Basic tier ($100/mo): Higher limits

## Reading (use bird)

For reading, searching, and monitoring — use the `bird` CLI:

```bash
bird home                    # Timeline
bird mentions                # Mentions
bird search "query"          # Search
bird user-tweets @handle     # User's posts
bird read <tweet-url>        # Single tweet
```

## Troubleshooting

**402 Credits Depleted**: Add credits in X Developer Portal → Dashboard

**401 Unauthorized**: Regenerate Access Token (ensure Read+Write permissions are set first)

**No credentials found**: Set env vars or create config file (see Setup above)

Overview

This skill posts to X (formerly Twitter) using the official API with OAuth 1.0a. It provides a reliable, authenticated way to publish tweets and threaded or multi-line posts. Use it when cookie-based or CLI posting is blocked or unreliable.

How this skill works

The skill uses developer credentials (API key/secret and access token/secret) to authenticate via OAuth 1.0a and call X endpoints. You supply text to the provided command or script and the skill sends a status update, returning the tweet URL on success. Credential configuration supports environment variables or a local JSON secrets file.

When to use it

  • You need to publish tweets or updates programmatically.
  • Cookie-based posting methods are blocked by bot detection.
  • You require official API reliability and rate management.
  • You want to post multi-line tweets or threaded content via scripts.
  • You need predictable error codes for automation and retries.

Best practices

  • Store API credentials securely in environment variables or a protected config file.
  • Set app permissions to Read and Write before generating tokens.
  • Handle 401 and 402 errors: regenerate tokens for 401, add credits for 402.
  • Rate-limit your posting logic to stay within your X Developer tier limits.
  • Log responses and tweet URLs to verify successful posts and for auditability.

Example use cases

  • Automated status updates from a CI/CD pipeline or deployment tool.
  • Cross-posting headlines or summaries from a blog or news aggregator.
  • Scheduled announcements or reminders from a scheduler or cron job.
  • Bot-managed account that posts curated content without relying on cookie scraping.
  • Publishing multi-line reports or structured updates from scripts.

FAQ

What credentials are required?

You need API Key (Consumer Key), API Key Secret, Access Token, and Access Token Secret with the app set to Read and Write.

How do I fix a 401 Unauthorized error?

Regenerate the access token after ensuring the app has Read+Write permissions, then update your stored credentials.