Skip to content
xdevplatformPublic

Latest commit

Β 

History

129 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

X API v2 Sample Code

X API v2

Official sample code for the X API v2 across Python, TypeScript, JavaScript, Java, C# / .NET, Ruby, and R.

First-party SDK samples use the official XDK libraries:

Repository Structure

β”œβ”€β”€ python/           # 80 Python samples (xdk)
β”œβ”€β”€ typescript/       # 84 TypeScript ESM samples (@xdevplatform/xdk, strict tsc)
β”œβ”€β”€ javascript/       # 84 JavaScript / Node.js CommonJS samples (@xdevplatform/xdk)
β”œβ”€β”€ java/             # 80 Java 17+ samples (com.x:xdk)
β”œβ”€β”€ csharp/           # 80 C# / .NET 8+ samples (XDevPlatform.Xdk)
β”œβ”€β”€ ruby/             # 58 Ruby samples
β”œβ”€β”€ r/                # 5 R samples
β”œβ”€β”€ llms.txt          # LLM-friendly documentation & SDK conventions
└── api-index.json    # Machine-readable endpoint-to-sample catalog

Quick Start

1. Get API Credentials

Sign up and create an App in the X Developer Console.

2. Set Environment Variables

For App-only read operations (search, lookup, streams, webhooks, activity):

export BEARER_TOKEN='your_bearer_token'

For User-context actions (post, like, repost, bookmark, DMs, media upload, etc.):

export CLIENT_ID='your_oauth2_client_id'
export CLIENT_SECRET='your_oauth2_client_secret'

3. Run an Example

# Python (xdk)
cd python && pip install xdk
python posts/search_recent.py

# TypeScript (@xdevplatform/xdk)
cd typescript && npm install
npx tsx posts/search_recent.ts

# JavaScript / Node.js (@xdevplatform/xdk)
cd javascript && npm install
node posts/search_recent.js

# Java 17+ (com.x:xdk)
cd java
mvn compile exec:java -Dexec.mainClass="posts.SearchRecent"

# C# / .NET 8+ (XDevPlatform.Xdk)
cd csharp
dotnet run -- posts/search_recent

# Ruby
cd ruby && bundle install
ruby posts/search_recent.rb

Coverage by Category

Category Python (xdk) TypeScript (@xdevplatform/xdk) JavaScript (@xdevplatform/xdk) Java (com.x:xdk) C# (XDevPlatform.Xdk) Ruby R
Activity (subscriptions & stream) βœ… βœ… βœ… βœ… βœ…
Compliance (batch jobs) βœ… βœ… βœ… βœ… βœ…
Direct Messages (1:1 & group DMs) βœ… βœ… βœ… βœ… βœ…
Lists (CRUD, members, followers, posts) βœ… βœ… βœ… βœ… βœ… βœ…
Media Upload (single & chunked v2) βœ… βœ… βœ… βœ… βœ…
Posts (search, counts, create, delete, hide reply, quotes) βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Spaces (lookup & search) βœ… βœ… βœ… βœ… βœ… βœ…
Streams (filtered rules & 1% sampled) βœ… βœ… βœ… βœ… βœ… βœ…
Usage (daily Post usage) βœ… βœ… βœ… βœ… βœ…
Users (lookup, timelines, likes, bookmarks, follows, mutes, blocks, reposts) βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Webhooks (register, list, validate CRC, delete, server) βœ… βœ… βœ… βœ… βœ…

Authentication

Type Use Case Env Vars
Bearer Token App-only endpoints (search, lookup, streams, webhooks, activity) BEARER_TOKEN
OAuth 2.0 PKCE User-context actions (post, like, repost, bookmark, mute, follow, DMs, media) CLIENT_ID, CLIENT_SECRET (or ACCESS_TOKEN)
Webhook HMAC Webhook CRC verification (webhook_server) CONSUMER_SECRET

For LLMs & Tooling

  • llms.txt - Concise context file covering SDK packages, auth patterns, pagination, and streaming across all languages
  • api-index.json - Machine-readable catalog mapping every endpoint to its exact file path in python/, typescript/, javascript/, java/, csharp/, ruby/, and r/

Resources

License

Apache 2.0

Used by

Contributors

Languages