samples  by xdevplatform

API v2 code samples for diverse operations

Created 5 years ago
3,129 stars

Top 15.3% on SourcePulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This repository provides working code samples for the X API v2, targeting developers needing to integrate with X's platform. It offers practical examples across multiple programming languages, enabling quick implementation of features like posting, user lookups, timeline management, and more, thereby accelerating development and reducing integration friction.

How It Works

The project is structured by programming language (Python, JavaScript, Ruby, Java, R), each containing numerous examples demonstrating specific X API v2 endpoints. It supports various authentication methods, including Bearer Token for read-only access, OAuth 1.0a for user actions, and OAuth 2.0 PKCE for newer functionalities. This multi-language, endpoint-focused approach simplifies learning and applying the X API.

Quick Start & Requirements

  • Install/Run: Navigate to the language-specific directory (e.g., cd python), install dependencies (pip install -r requirements.txt for Python, npm install for JavaScript, bundle install for Ruby), then execute example scripts (e.g., python posts/recent_search.py).
  • Prerequisites: X API v2 credentials (API Key, API Secret, Bearer Token) obtained from the X Developer Portal. Environment variables (BEARER_TOKEN, CONSUMER_KEY, CONSUMER_SECRET) must be set.
  • Links: X API Documentation, X Developer Portal.

Highlighted Details

  • Comprehensive coverage of X API v2 functionalities, including Posts, Users, Timelines, Streams, Lists, Spaces, Bookmarks, Direct Messages, Media Upload, Compliance, and Usage.
  • Supports multiple languages: Python (108 examples), JavaScript (70), Ruby (58), Java (19), and R (5).
  • Includes llms.txt for LLM-friendly documentation and api-index.json as a machine-readable endpoint catalog.
  • Demonstrates three distinct authentication flows: Bearer Token, OAuth 1.0a, and OAuth 2.0 PKCE.

Maintenance & Community

No specific details on contributors, sponsorships, or community channels (like Discord/Slack) are provided in the README.

Licensing & Compatibility

Licensed under Apache 2.0. This license is permissive and generally compatible with commercial use and closed-source projects.

Limitations & Caveats

The repository contains only sample code; it does not provide a full SDK or framework. Specific examples might require updates as the X API evolves. Direct Messages and Media Upload examples are currently limited to Python.

Health Check
Last Commit

2 months ago

Responsiveness

Inactive

Pull Requests (30d)
1
Issues (30d)
0
Star History
32 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Ishaan Jaffer Ishaan Jaffer(Cofounder of LiteLLM), and
10 more.

llama-stack by llamastack

0.1%
8k
Composable building blocks for Llama apps
Created 1 year ago
Updated 1 day ago
Feedback? Help us improve.