Skip to content

jmartinn/x-api-typescript-sdk

 
 

X API SDK for TypeScript

Introduction

A TypeScript SDK for the X API (formerly Twitter API), built with modern TypeScript practices. This SDK is designed with developers in mind, providing full type safety, ease of use, and support for the latest X API features.

Note: This SDK is currently under development and not ready for production use.

This project is a fork of the official Twitter API SDK and has been rebranded and updated to support the latest X API functionality.

Features

  • Full type safety: Comprehensive type definitions for requests and responses.
  • OAuth2 support: Authenticate securely using X's OAuth2 mechanisms.
  • Built for modern Node.js: Supports Node.js 16+.
  • Streaming support: Easy-to-use Async Generators for real-time data.
  • Pagination made simple: Handle paginated endpoints seamlessly.

Installing

npm install x-api-sdk

Quick Start

Setting Up the Client

import { Client } from 'x-api-sdk';

const client = new Client('MY-BEARER-TOKEN');

Examples

Consuming a Stream

const stream = client.tweets.sampleStream({
  'tweet.fields': ['author_id'],
});
for await (const tweet of stream) {
  console.log(tweet.data?.author_id);
}

Fetching a Tweet

const tweet = await client.tweets.findTweetById('20');
console.log(tweet.data?.text);

Authentication

This SDK supports App-only Bearer Tokens and OAuth 2.0 authentication. See X API documentation for more details.

Contributing

We welcome contributions to the SDK! If you're interested in helping, here's how to get started:

  1. Clone the Repository:

    git clone https://github.com/<your-username>/x-api-typescript-sdk
  2. Install Dependencies:

    pnpm install
  3. Run the Generation Script: Generate the SDK using the latest OpenAPI spec:

    pnpm generate
  4. Build:

    pnpm build
  5. Test:

    pnpm test

Acknowledgments

This SDK is based on the original twitter-api-typescript-sdk, originally developed by Twitter, Inc. under the Apache 2.0 license.

License

This project is licensed under the Apache 2.0 license. See the LICENSE file for details.

Packages

No packages published

Languages

  • TypeScript 100.0%