GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - xdevplatform/samples: Sample code for the X API v2 endpoints

BranchesTags
Open more actions menu

Latest commit

 

History

128 Commits
128 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
java
java
 
 
javascript
javascript
 
 
python
python
 
 
r
r
 
 
ruby
ruby
 
 
.gitignore
.gitignore
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
api-index.json
api-index.json
 
 
llms.txt
llms.txt
 
 

Repository files navigation

X API v2 Sample Code

X API v2

Working code samples for the X API v2 in Python, JavaScript, Ruby, Java, and R.

šŸ“ Repository Structure

ā”œā”€ā”€ python/           # 65 Python examples
ā”œā”€ā”€ javascript/       # 59 JavaScript examples  
ā”œā”€ā”€ ruby/             # 58 Ruby examples
ā”œā”€ā”€ java/             # 19 Java examples
ā”œā”€ā”€ r/                # 5 R examples
ā”œā”€ā”€ llms.txt          # LLM-friendly documentation
└── api-index.json    # Machine-readable endpoint catalog

šŸš€ Quick Start

1. Get API Credentials

Sign up at the X Developer Portal.

2. Set Environment Variables

For read-only operations (search, lookup):

export BEARER_TOKEN='your_bearer_token'

For user actions (post, like, repost, bookmark, etc.):

export CLIENT_ID='your_client_id'
export CLIENT_SECRET='your_client_secret'

For OAuth 1.0a (legacy endpoints):

export CONSUMER_KEY='your_consumer_key'
export CONSUMER_SECRET='your_consumer_secret'

3. Run an Example

# Python
cd python && pip install -r requirements.txt
python posts/search_recent.py

# JavaScript  
cd javascript
node posts/search_recent.js

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

# Java
cd java
javac -cp ".:lib/*" posts/RecentSearchDemo.java
java -cp ".:lib/*" RecentSearchDemo

šŸ“š Examples by Category

Category Python JavaScript Ruby Java R
Posts (search, create, delete, likes, reposts) āœ… āœ… āœ… āœ… āœ…
Users (lookup, followers, following, blocks, mutes) āœ… āœ… āœ… āœ… āœ…
Timelines (user, mentions, home) āœ… āœ… āœ… āœ…
Streams (filtered, sampled) āœ… āœ… āœ… āœ…
Lists (lookup, manage, members, follow) āœ… āœ… āœ…
Spaces (lookup, search) āœ… āœ… āœ… āœ…
Bookmarks āœ… āœ… āœ…
Direct Messages āœ…
Media Upload āœ…
Compliance āœ… āœ…
Usage āœ… āœ… āœ…

šŸ” Authentication

Type Use Case Env Vars
Bearer Token Read-only (search, lookup) BEARER_TOKEN
OAuth 2.0 PKCE User actions (post, like, repost, bookmark, mute, etc.) CLIENT_ID, CLIENT_SECRET
OAuth 1.0a Legacy endpoints (if applicable) CONSUMER_KEY, CONSUMER_SECRET

šŸ¤– For LLMs

  • llms.txt - Context file for AI assistants
  • api-index.json - Machine-readable endpoint catalog

šŸ”— Resources

  • X API Documentation
  • Developer Portal

šŸ“„ License

Apache 2.0

About

Sample code for the X API v2 endpoints

docs.x.com/x-api/getting-started/about-x-api

Topics

javajavascriptnodejspythonrubytwittertwitter-apitwitter-api-v2

Resources

Readme
Apache-2.0 license

Code of conduct

Code of conduct
Activity
Custom properties

Stars

3.2k stars

Watchers

71 watching

Forks

1.1k forks
Report repository

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Ɨ600. No cookies required.