diff --git a/docs.json b/docs.json index 278bf755a..59f401df5 100644 --- a/docs.json +++ b/docs.json @@ -1035,7 +1035,7 @@ "dropdowns": [ { "dropdown": "Overview", - "description": "Compare all 4 official SDKs", + "description": "Python, TypeScript, Java, C#", "icon": "cubes", "groups": [ { @@ -1045,56 +1045,56 @@ ] }, { - "group": "Official Repositories", + "group": "GitHub", "pages": [ { "type": "link", - "title": "Python SDK (GitHub)", + "title": "xdk-python", "href": "https://github.com/xdevplatform/xdk-python" }, { "type": "link", - "title": "TypeScript SDK (GitHub)", + "title": "xdk-typescript", "href": "https://github.com/xdevplatform/xdk-typescript" }, { "type": "link", - "title": "Java SDK (GitHub)", + "title": "xdk-java", "href": "https://github.com/xdevplatform/xdk-java" }, { "type": "link", - "title": "C# SDK (GitHub)", + "title": "xdk-csharp", "href": "https://github.com/xdevplatform/xdk-csharp" }, { "type": "link", - "title": "SDK Generator (Rust)", + "title": "xdk (Generator)", "href": "https://github.com/xdevplatform/xdk" } ] }, { - "group": "Package Registries", + "group": "Packages", "pages": [ { "type": "link", - "title": "PyPI — xdk", + "title": "PyPI (xdk)", "href": "https://pypi.org/project/xdk/" }, { "type": "link", - "title": "npm — @xdevplatform/xdk", + "title": "npm (@xdevplatform/xdk)", "href": "https://www.npmjs.com/package/@xdevplatform/xdk" }, { "type": "link", - "title": "Maven Central — com.x:xdk", + "title": "Maven Central (com.x:xdk)", "href": "https://central.sonatype.com/artifact/com.x/xdk" }, { "type": "link", - "title": "NuGet — XDevPlatform.Xdk", + "title": "NuGet (XDevPlatform.Xdk)", "href": "https://www.nuget.org/packages/XDevPlatform.Xdk" } ] @@ -1103,7 +1103,7 @@ }, { "dropdown": "Python", - "description": "pip install xdk", + "description": "xdk", "icon": "python", "groups": [ { @@ -1151,7 +1151,7 @@ }, { "dropdown": "TypeScript", - "description": "npm i @xdevplatform/xdk", + "description": "@xdevplatform/xdk", "icon": "js", "groups": [ { @@ -1199,7 +1199,7 @@ }, { "dropdown": "Java", - "description": "com.x:xdk (Maven)", + "description": "com.x:xdk", "icon": "java", "groups": [ { @@ -1247,7 +1247,7 @@ }, { "dropdown": "C#", - "description": "XDevPlatform.Xdk (NuGet)", + "description": "XDevPlatform.Xdk", "icon": "code", "groups": [ { diff --git a/tools-and-libraries.mdx b/tools-and-libraries.mdx index 18fc561c5..bf521aa06 100644 --- a/tools-and-libraries.mdx +++ b/tools-and-libraries.mdx @@ -13,20 +13,20 @@ Speed up your development with official SDKs, CLI tools, AI agent integrations, ## Official SDKs (XDKs) -Generated directly from the X API v2 OpenAPI specification with built-in authentication, pagination, and real-time streaming. +Client libraries for the X API v2, generated from the OpenAPI spec with auth, pagination, and streaming built in. - - `pip install xdk` — Pydantic models, iterator pagination, OAuth 2.0 PKCE, and streaming for Python 3.8+. + + `pip install xdk` · Python 3.8+ - - `npm install @xdevplatform/xdk` — Full TypeScript definitions, dual ESM/CJS builds, and event-driven streaming for Node.js 18+. + + `npm install @xdevplatform/xdk` · Node.js 18+ - - `com.x:xdk` on Maven Central — Fluent builders, `Paginator`, and `AutoCloseable` `EventStream` for Java 17+. + + `com.x:xdk` · Java 17+ - - `XDevPlatform.Xdk` on NuGet — Zero external runtime dependencies, `async`/`await`, and `IAsyncEnumerable` for .NET 8+. + + `dotnet add package XDevPlatform.Xdk` · .NET 8+ diff --git a/tools/csharp-xdk.mdx b/tools/csharp-xdk.mdx index 302398821..0e8dbc40e 100644 --- a/tools/csharp-xdk.mdx +++ b/tools/csharp-xdk.mdx @@ -1,18 +1,18 @@ --- title: C# / .NET XDK sidebarTitle: C# -description: Install and use the official C# / .NET XDK client library (XDevPlatform.Xdk) for the X API v2 with async/await, IAsyncEnumerable pagination, and EventStream. +description: C# and .NET client library for the X API v2. keywords: ["C# SDK", ".NET SDK", "XDK", "C#", "dotnet", "NuGet", "XDevPlatform.Xdk", "X API"] --- -The [C# / .NET XDK](https://github.com/xdevplatform/xdk-csharp) (`XDevPlatform.Xdk` on NuGet) is the official .NET client library for the X API v2, targeting .NET 8+ with zero external runtime dependencies (`System.Net.Http` and `System.Text.Json`), `CancellationToken` support on every call, `Paginator`, and `EventStream`. +`XDevPlatform.Xdk` ([GitHub](https://github.com/xdevplatform/xdk-csharp)) is the official C# / .NET client library for the X API v2 (.NET 8+). - - `dotnet add package XDevPlatform.Xdk` — .NET 8.0+. + + `dotnet add package XDevPlatform.Xdk` · .NET 8+ - - Source code, runnable examples, and issue tracker. + + Source code and issues. @@ -125,22 +125,22 @@ using var client = new XClient(new XClientOptions { OAuth1 = oauth1 }); ## Learn more - - .NET CLI, csproj configuration, and DI setup. + + Add `XDevPlatform.Xdk` from NuGet. - Step-by-step first request walkthrough. + Make your first request. - Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a guides. + Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a. - `IAsyncEnumerable` paging via `*Pages(...)` methods. + Iterate pages with `await foreach`. - `await using` + `await foreach` on `EventStream`. + Read live streams with `EventStream`. - Complete reference for all 24 resource clients. + Methods and parameters for each client. diff --git a/tools/java-xdk.mdx b/tools/java-xdk.mdx index d0099d249..3368ded9c 100644 --- a/tools/java-xdk.mdx +++ b/tools/java-xdk.mdx @@ -1,18 +1,18 @@ --- title: Java XDK sidebarTitle: Java -description: Install and use the official Java XDK client library (com.x:xdk) for the X API v2 with fluent builders, OAuth 2.0 PKCE, Paginator, and EventStream. +description: Java client library for the X API v2. keywords: ["Java SDK", "XDK", "Java", "Kotlin", "Maven", "Gradle", "com.x:xdk", "X API"] --- -The [Java XDK](https://github.com/xdevplatform/xdk-java) (`com.x:xdk` on Maven Central) is the official JVM client library for the X API v2, targeting Java 17+ (including Java 21, Kotlin, and Scala) with strongly typed Jackson models, `Paginator`, and `AutoCloseable` `EventStream`. +`com.x:xdk` ([GitHub](https://github.com/xdevplatform/xdk-java)) is the official Java client library for the X API v2 (Java 17+ and Kotlin). - `com.x:xdk:0.1.2` — Java 17+. + `com.x:xdk:0.1.2` · Java 17+ - - Source code, runnable examples, and issue tracker. + + Source code and issues. @@ -131,22 +131,22 @@ XClient client = XClient.builder().oauth1(oauth1).build(); ## Learn more - - Maven, Gradle, JDK requirements, and build setup. + + Add `com.x:xdk` with Maven or Gradle. - Step-by-step first request walkthrough. + Make your first request. - Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a guides. + Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a. - `Paginator` cursor iteration via `*Pages(...)` methods. + Iterate pages with `Paginator`. - `EventStream` with `try-with-resources` and auto-reconnect. + Read live streams with `EventStream`. - Complete reference for all 24 resource clients. + Methods and parameters for each client. diff --git a/tools/python-xdk.mdx b/tools/python-xdk.mdx index 9a41f6614..8ebf7fc3f 100644 --- a/tools/python-xdk.mdx +++ b/tools/python-xdk.mdx @@ -1,18 +1,18 @@ --- title: Python XDK sidebarTitle: Python -description: Install and use the official Python XDK client library for the X API v2, including authentication setup, paginated requests, and streaming examples. +description: Python client library for the X API v2. keywords: ["Python SDK", "XDK", "Python", "X API", "client library", "pip", "xdk"] --- -The [Python XDK](https://github.com/xdevplatform/xdk-python) (`xdk` on PyPI) is the official Python client library for the X API v2, providing Pydantic v2 models, automatic pagination, OAuth helpers, and streaming. +`xdk` ([GitHub](https://github.com/xdevplatform/xdk-python)) is the official Python client library for the X API v2. - - `pip install xdk` — Python 3.8+. + + `pip install xdk` · Python 3.8+ - - Source code, release notes, and issue tracker. + + Source code and issues. @@ -106,22 +106,22 @@ client = Client(auth=oauth1) ## Learn more - - Virtual environments, editable installs, and verification. + + Install with pip, uv, or poetry. - Step-by-step first request walkthrough. + Run your first search query. - Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a guides. + Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a. - Automatic iterator pagination and manual cursors. + Iterate across multi-page endpoints. - Filtered stream, sample stream, and rule management. + Filtered streams and rule management. - Complete reference for all 24 resource clients. + Methods and parameters for each client. diff --git a/tools/typescript-xdk.mdx b/tools/typescript-xdk.mdx index b2ebd5914..b6f27407d 100644 --- a/tools/typescript-xdk.mdx +++ b/tools/typescript-xdk.mdx @@ -1,18 +1,18 @@ --- title: TypeScript XDK sidebarTitle: TypeScript -description: Install and use the official TypeScript XDK client library for the X API v2, with authentication, typed responses, pagination, and streaming examples. +description: TypeScript and JavaScript client library for the X API v2. keywords: ["TypeScript SDK", "XDK", "TypeScript", "JavaScript", "X API", "client library", "npm", "@xdevplatform/xdk"] --- -The [TypeScript XDK](https://github.com/xdevplatform/xdk-typescript) (`@xdevplatform/xdk` on npm) is the official TypeScript and JavaScript client library for the X API v2, featuring full TypeScript types, dual ESM/CommonJS builds, async paginators, and event-driven streaming. +`@xdevplatform/xdk` ([GitHub](https://github.com/xdevplatform/xdk-typescript)) is the official TypeScript and JavaScript client library for the X API v2. - - `npm install @xdevplatform/xdk` — Node.js 18+. + + `npm install @xdevplatform/xdk` · Node.js 18+ - - Source code, release notes, and issue tracker. + + Source code and issues. @@ -117,22 +117,22 @@ const client = new Client({ oauth1 }); ## Learn more - - Package managers, ESM/CommonJS usage, and requirements. + + Install with npm, pnpm, yarn, or bun. - Step-by-step first request walkthrough. + Make your first request. - Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a guides. + Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a. - `UserPaginator`, `PostPaginator`, and async iteration. + Async iteration and manual paging. - `EventDrivenStream` listeners and `for await` consumption. + Event listeners and async iteration. - Complete reference for all 24 resource clients. + Methods and parameters for each client. diff --git a/xdks/csharp/authentication.mdx b/xdks/csharp/authentication.mdx index 6180334c5..a653a0b88 100644 --- a/xdks/csharp/authentication.mdx +++ b/xdks/csharp/authentication.mdx @@ -1,16 +1,12 @@ --- -title: C# Authentication +title: Authentication sidebarTitle: Authentication -description: Authenticate the C# / .NET XDK (XDevPlatform.Xdk) using Bearer Tokens, OAuth 2.0 PKCE with token refresh, or OAuth 1.0a user context. +description: Configure Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a in the C# / .NET XDK. --- -`XClient` supports all three X API v2 authentication modes through `XClientOptions`: +`XClient` supports Bearer Token (app-only), OAuth 2.0 with PKCE (user context), and OAuth 1.0a (user context) via `XClientOptions`. Get your credentials from the [X Developer Console](https://console.x.com). -1. **Bearer Token (App-Only)** — Public read, search, and filtered/sample streaming endpoints. -2. **OAuth 2.0 User Context with PKCE** — Scoped user-authorized calls (`POST /2/tweets`, bookmarks, DMs, X Chat) with refresh token support. -3. **OAuth 1.0a User Context** — HMAC-SHA1 request signing. - -## 1. Bearer Token (App-Only) +## Bearer Token ```csharp using System; @@ -24,9 +20,9 @@ using var client = new XClient(new XClientOptions var user = await client.Users.GetByUsernameAsync("XDevelopers"); ``` -## 2. OAuth 2.0 User Context with PKCE +## OAuth 2.0 with PKCE -If you already hold an OAuth 2.0 user access token: +If you already have a user access token: ```csharp using var client = new XClient(new XClientOptions @@ -37,7 +33,7 @@ using var client = new XClient(new XClientOptions var me = await client.Users.GetMeAsync(); ``` -To run the full RFC 7636 PKCE authorization flow and enable token refresh via `OAuth2Pkce`: +To run the PKCE authorization flow and refresh tokens with `OAuth2Pkce`: ```csharp using System; @@ -52,13 +48,13 @@ var oauth2 = new OAuth2Pkce( scopes: new[] { "tweet.read", "tweet.write", "users.read", "offline.access" } ); -// 1. Direct the user to authorize your application +// 1. Direct the user to authorize your app string authorizationUrl = oauth2.GetAuthorizationUrl("random-csrf-state"); -// 2. Exchange the authorization code from the callback URL +// 2. Exchange the callback `code` parameter for tokens OAuth2Token token = await oauth2.ExchangeCodeAsync(callbackCode); -// 3. Create XClient bound to the OAuth2Pkce manager +// 3. Create XClient with the OAuth2Pkce instance using var client = new XClient(new XClientOptions { OAuth2 = oauth2, @@ -69,11 +65,11 @@ var created = await client.Posts.CreateAsync(new CreatePostsRequest Text = "Hello from C# XDK!", }); -// Refresh tokens explicitly when needed (requires offline.access scope) +// Refresh tokens when needed (requires offline.access scope) await client.RefreshTokenAsync(); ``` -## 3. OAuth 1.0a User Context +## OAuth 1.0a ```csharp using System; @@ -95,3 +91,5 @@ using var client = new XClient(new XClientOptions var me = await client.Users.GetMeAsync(); ``` + +See the [C# samples repo](https://github.com/xdevplatform/samples/tree/main/csharp) for more examples. diff --git a/xdks/csharp/install.mdx b/xdks/csharp/install.mdx index 5aab7ccae..ab5e6e9c7 100644 --- a/xdks/csharp/install.mdx +++ b/xdks/csharp/install.mdx @@ -1,17 +1,10 @@ --- -title: Install C# / .NET XDK +title: Install sidebarTitle: Install -description: Install the official C# / .NET XDK (XDevPlatform.Xdk) from NuGet for .NET 8.0 and newer projects. +description: Add the C# / .NET XDK from NuGet. --- -Install `XDevPlatform.Xdk` from [NuGet.org](https://www.nuget.org/packages/XDevPlatform.Xdk). - -## Prerequisites - -- **.NET 8.0 SDK** or newer (`.NET 8`, `.NET 9`) -- Zero external NuGet runtime dependencies required - -## Add Package +Install `XDevPlatform.Xdk` from [NuGet](https://www.nuget.org/packages/XDevPlatform.Xdk). Requires .NET 8.0+. @@ -31,7 +24,7 @@ Install-Package XDevPlatform.Xdk -## Custom `HttpClient` Integration +## Custom `HttpClient` In ASP.NET Core or worker services using `IHttpClientFactory`, pass a managed `HttpClient` via `XClientOptions.HttpClient`: @@ -47,7 +40,7 @@ var client = new XClient(new XClientOptions }); ``` -## Build from Source +## Build from source ```bash git clone https://github.com/xdevplatform/xdk-csharp.git @@ -55,8 +48,8 @@ cd xdk-csharp dotnet test ``` -## Next Steps +## Next steps -- [Quickstart](/xdks/csharp/quickstart) — Make your first request -- [Authentication](/xdks/csharp/authentication) — Configure Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a -- [API Reference](/xdks/csharp/reference/overview) — Explore all 24 resource clients +- [Quickstart](/xdks/csharp/quickstart) +- [Authentication](/xdks/csharp/authentication) +- [API Reference](/xdks/csharp/reference/overview) diff --git a/xdks/csharp/llms.txt b/xdks/csharp/llms.txt index 2d1864d26..518573ccb 100644 --- a/xdks/csharp/llms.txt +++ b/xdks/csharp/llms.txt @@ -1,19 +1,19 @@ # C# XDK (`XDevPlatform.Xdk` v0.1.2) -> Official C# SDK for the X API v2 (.NET 8.0+). Install with `dotnet add package XDevPlatform.Xdk`. +> Official C# client library for the X API v2 (.NET 8.0+). Install with `dotnet add package XDevPlatform.Xdk`. ## Guides -- [C# overview](https://docs.x.com/xdks/csharp/overview.md): Architecture, capabilities, and client overview -- [C# install](https://docs.x.com/xdks/csharp/install.md): Package installation and runtime requirements -- [C# quickstart](https://docs.x.com/xdks/csharp/quickstart.md): First authenticated X API v2 request in under 2 minutes -- [C# authentication](https://docs.x.com/xdks/csharp/authentication.md): Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a user-context setup -- [C# pagination](https://docs.x.com/xdks/csharp/pagination.md): Automatic cursor iteration across multi-page endpoints -- [C# streaming](https://docs.x.com/xdks/csharp/streaming.md): Real-time event streams with reconnection and lifecycle handling +- [C# overview](https://docs.x.com/xdks/csharp/overview.md): Overview and quick example +- [C# install](https://docs.x.com/xdks/csharp/install.md): Installation and requirements +- [C# quickstart](https://docs.x.com/xdks/csharp/quickstart.md): Make your first X API v2 request +- [C# authentication](https://docs.x.com/xdks/csharp/authentication.md): Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a +- [C# pagination](https://docs.x.com/xdks/csharp/pagination.md): Cursor pagination across multi-page endpoints +- [C# streaming](https://docs.x.com/xdks/csharp/streaming.md): Real-time event streams and filtered stream rules ## Client Reference -- [Reference Overview](https://docs.x.com/xdks/csharp/reference/overview.md): Main client options and resource client directory +- [Reference Overview](https://docs.x.com/xdks/csharp/reference/overview.md): Client options and client list - [`AccountClient` (Account)](https://docs.x.com/xdks/csharp/reference/clients/account.md): 2 methods via `client.Account` - [`AccountActivityClient` (Account Activity)](https://docs.x.com/xdks/csharp/reference/clients/account-activity.md): 5 methods via `client.AccountActivity` - [`ActivityClient` (Activity)](https://docs.x.com/xdks/csharp/reference/clients/activity.md): 5 methods via `client.Activity` diff --git a/xdks/csharp/overview.mdx b/xdks/csharp/overview.mdx index 852ea6886..4f1fc289e 100644 --- a/xdks/csharp/overview.mdx +++ b/xdks/csharp/overview.mdx @@ -1,29 +1,21 @@ --- title: C# / .NET XDK sidebarTitle: Overview -description: Official C# and .NET SDK (XDevPlatform.Xdk) for the X API v2 targeting .NET 8+ with zero external runtime dependencies, IAsyncEnumerable pagination, and EventStream. +description: C# and .NET client library for the X API v2. --- -The **C# / .NET XDK** (`XDevPlatform.Xdk`) is X's official .NET client library for the X API v2, generated directly from the [official OpenAPI specification](https://api.x.com/2/openapi.json) and published on NuGet. +`XDevPlatform.Xdk` is the official C# / .NET SDK for the X API v2 (.NET 8+). It uses `System.Net.Http` and `System.Text.Json` with no extra runtime dependencies, async methods with `CancellationToken`, `IAsyncEnumerable` pagination, and `EventStream`. - - `dotnet add package XDevPlatform.Xdk` — .NET 8.0+. + + `dotnet add package XDevPlatform.Xdk` · .NET 8+ - - Source code, runnable examples, and issue tracker. + + Source code and issues. -## Key Features - -- **Zero External Runtime Dependencies**: Built entirely on `System.Net.Http.HttpClient` and `System.Text.Json` for .NET 8+. -- **First-Class Async & Cancellation**: Every endpoint method is `async` (`*Async`), accepts a `CancellationToken`, and `XClient` implements `IDisposable`. -- **Authentication**: App-only Bearer Token, OAuth 2.0 User Context with PKCE (`OAuth2Pkce`) and token refresh, and OAuth 1.0a HMAC-SHA1 (`OAuth1`). -- **Async Pagination (`IAsyncEnumerable`)**: Paginated endpoints expose `*Pages(...)` returning `Paginator`, enabling native `await foreach` loops. -- **Resilient Streaming (`IAsyncDisposable`)**: Streaming endpoints return `EventStream` supporting `await using` and `await foreach` with incremental UTF-8 line decoding and exponential backoff reconnection. - -## Quick Example +## Quick example ```csharp using System; @@ -46,25 +38,25 @@ var response = await client.Users.GetByUsernameAsync( Console.WriteLine(response.Data); ``` -## Guides & Reference +## Guides - Add `XDevPlatform.Xdk` via the .NET CLI or NuGet. + Add `XDevPlatform.Xdk` from NuGet. - Make your first X API v2 request in C#. + Make your first request. - Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a setup. + Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a. - Iterate pages lazily with `await foreach`. + Iterate pages with `await foreach`. - Consume live NDJSON streams with `EventStream`. + Read live streams with `EventStream`. - - Full method & parameter reference for all 24 clients. + + Methods and parameters for each client. diff --git a/xdks/csharp/pagination.mdx b/xdks/csharp/pagination.mdx index e0ba72caf..3c42fcf65 100644 --- a/xdks/csharp/pagination.mdx +++ b/xdks/csharp/pagination.mdx @@ -1,12 +1,12 @@ --- -title: C# Pagination +title: Pagination sidebarTitle: Pagination -description: Automatically iterate paginated X API v2 endpoints in C# using IAsyncEnumerable and *Pages(...) methods. +description: Paginate X API v2 responses in C# with IAsyncEnumerable or manual tokens. --- -Every paginated endpoint in the C# XDK exposes a companion `*Pages(...)` method returning `Paginator` (`IAsyncEnumerable`), which lazily fetches subsequent pages via `meta.next_token` as you iterate with `await foreach`. +Paginated endpoints expose a `*Pages(...)` method returning `Paginator` (`IAsyncEnumerable`), which fetches pages lazily using `meta.next_token` as you iterate with `await foreach`. -## Automatic Async Pagination (`*Pages`) +## Automatic pagination (`*Pages`) ```csharp using System; @@ -33,14 +33,14 @@ await foreach (var page in client.Posts.SearchRecentPages( Console.WriteLine($"Fetched {page.Data?.Count ?? 0} posts"); if (++pageCount >= 5) { - break; // Stops immediately without issuing additional HTTP requests + break; // Stop early without extra requests } } ``` -## Manual Cursor Control +## Manual pagination -If you need to persist pagination tokens across separate requests or background jobs, call the single-page `*Async` method with `PaginationToken`: +Call the single-page `*Async` method directly with `PaginationToken`: ```csharp var firstPage = await client.Posts.SearchRecentAsync( diff --git a/xdks/csharp/quickstart.mdx b/xdks/csharp/quickstart.mdx index 92f7f823f..5127b85b8 100644 --- a/xdks/csharp/quickstart.mdx +++ b/xdks/csharp/quickstart.mdx @@ -1,27 +1,25 @@ --- -title: C# Quickstart +title: Quickstart sidebarTitle: Quickstart -description: Make your first X API v2 request in C# (.NET 8+) using XDevPlatform.Xdk and a Bearer Token. +description: Make your first X API v2 request with the C# / .NET XDK. --- -Make your first authenticated X API v2 call with `XDevPlatform.Xdk` in minutes. - - + ```bash dotnet new console -n XdkQuickstart cd XdkQuickstart dotnet add package XDevPlatform.Xdk ``` - - Generate a **Bearer Token** in the [X Developer Console](https://console.x.com) and export it in your shell: + + Generate a **Bearer Token** in the [X Developer Console](https://console.x.com) and set it in your shell: ```bash export X_BEARER_TOKEN="your_bearer_token_here" ``` - + ```csharp using System; using System.Collections.Generic; @@ -46,13 +44,13 @@ var posts = await client.Posts.SearchRecentAsync( Console.WriteLine($"Posts returned: {posts.Data?.Count ?? 0}"); ``` - Run your app with `dotnet run`. + Run it with `dotnet run`. -## Next Steps +## Next steps -- [Authentication](/xdks/csharp/authentication) — Act on behalf of users with OAuth 2.0 PKCE or OAuth 1.0a -- [Pagination](/xdks/csharp/pagination) — Stream pages lazily with `await foreach` -- [Streaming](/xdks/csharp/streaming) — Subscribe to live streams with `EventStream` -- [Client Reference](/xdks/csharp/reference/overview) — Browse all 24 resource clients +- [Authentication](/xdks/csharp/authentication) — Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a +- [Pagination](/xdks/csharp/pagination) — Iterate pages with `await foreach` +- [Streaming](/xdks/csharp/streaming) — Read live streams with `EventStream` +- [Code samples](https://github.com/xdevplatform/samples/tree/main/csharp) — Runnable C# examples diff --git a/xdks/csharp/reference/clients/account-activity.mdx b/xdks/csharp/reference/clients/account-activity.mdx index dc03d10fe..edf46e8d6 100644 --- a/xdks/csharp/reference/clients/account-activity.mdx +++ b/xdks/csharp/reference/clients/account-activity.mdx @@ -1,7 +1,7 @@ --- -title: "AccountActivityClient (C# XDK)" +title: "AccountActivityClient" sidebarTitle: "Account Activity" -description: "C# XDK AccountActivityClient reference — 5 methods for X API v2 Account Activity endpoints." +description: "Methods for X API v2 Account Activity endpoints." --- Access **Account Activity** endpoints via `client.AccountActivity` (`AccountActivityClient`). diff --git a/xdks/csharp/reference/clients/account.mdx b/xdks/csharp/reference/clients/account.mdx index d194976e6..8bebf2e5b 100644 --- a/xdks/csharp/reference/clients/account.mdx +++ b/xdks/csharp/reference/clients/account.mdx @@ -1,7 +1,7 @@ --- -title: "AccountClient (C# XDK)" +title: "AccountClient" sidebarTitle: "Account" -description: "C# XDK AccountClient reference — 2 methods for X API v2 Account endpoints." +description: "Methods for X API v2 Account endpoints." --- Access **Account** endpoints via `client.Account` (`AccountClient`). diff --git a/xdks/csharp/reference/clients/activity.mdx b/xdks/csharp/reference/clients/activity.mdx index 56ebc60c2..b6ec7ca38 100644 --- a/xdks/csharp/reference/clients/activity.mdx +++ b/xdks/csharp/reference/clients/activity.mdx @@ -1,7 +1,7 @@ --- -title: "ActivityClient (C# XDK)" +title: "ActivityClient" sidebarTitle: "Activity" -description: "C# XDK ActivityClient reference — 5 methods for X API v2 Activity endpoints." +description: "Methods for X API v2 Activity endpoints." --- Access **Activity** endpoints via `client.Activity` (`ActivityClient`). diff --git a/xdks/csharp/reference/clients/articles.mdx b/xdks/csharp/reference/clients/articles.mdx index 7b0bb73f6..788ee56e8 100644 --- a/xdks/csharp/reference/clients/articles.mdx +++ b/xdks/csharp/reference/clients/articles.mdx @@ -1,7 +1,7 @@ --- -title: "ArticlesClient (C# XDK)" +title: "ArticlesClient" sidebarTitle: "Articles" -description: "C# XDK ArticlesClient reference — 2 methods for X API v2 Articles endpoints." +description: "Methods for X API v2 Articles endpoints." --- Access **Articles** endpoints via `client.Articles` (`ArticlesClient`). diff --git a/xdks/csharp/reference/clients/bots.mdx b/xdks/csharp/reference/clients/bots.mdx index be895c7c9..bd9dfa228 100644 --- a/xdks/csharp/reference/clients/bots.mdx +++ b/xdks/csharp/reference/clients/bots.mdx @@ -1,7 +1,7 @@ --- -title: "BotsClient (C# XDK)" +title: "BotsClient" sidebarTitle: "Bots" -description: "C# XDK BotsClient reference — 6 methods for X API v2 Bots endpoints." +description: "Methods for X API v2 Bots endpoints." --- Access **Bots** endpoints via `client.Bots` (`BotsClient`). diff --git a/xdks/csharp/reference/clients/broadcasts.mdx b/xdks/csharp/reference/clients/broadcasts.mdx index 830248f2f..a5b1f1182 100644 --- a/xdks/csharp/reference/clients/broadcasts.mdx +++ b/xdks/csharp/reference/clients/broadcasts.mdx @@ -1,7 +1,7 @@ --- -title: "BroadcastsClient (C# XDK)" +title: "BroadcastsClient" sidebarTitle: "Broadcasts" -description: "C# XDK BroadcastsClient reference — 41 methods for X API v2 Broadcasts endpoints." +description: "Methods for X API v2 Broadcasts endpoints." --- Access **Broadcasts** endpoints via `client.Broadcasts` (`BroadcastsClient`). diff --git a/xdks/csharp/reference/clients/calls.mdx b/xdks/csharp/reference/clients/calls.mdx index c2b519140..b2be079f5 100644 --- a/xdks/csharp/reference/clients/calls.mdx +++ b/xdks/csharp/reference/clients/calls.mdx @@ -1,7 +1,7 @@ --- -title: "CallsClient (C# XDK)" +title: "CallsClient" sidebarTitle: "Calls" -description: "C# XDK CallsClient reference — 10 methods for X API v2 Calls endpoints." +description: "Methods for X API v2 Calls endpoints." --- Access **Calls** endpoints via `client.Calls` (`CallsClient`). diff --git a/xdks/csharp/reference/clients/chat.mdx b/xdks/csharp/reference/clients/chat.mdx index 3a7256bd9..315cb1bd9 100644 --- a/xdks/csharp/reference/clients/chat.mdx +++ b/xdks/csharp/reference/clients/chat.mdx @@ -1,7 +1,7 @@ --- -title: "ChatClient (C# XDK)" +title: "ChatClient" sidebarTitle: "Chat" -description: "C# XDK ChatClient reference — 45 methods for X API v2 Chat endpoints." +description: "Methods for X API v2 Chat endpoints." --- Access **Chat** endpoints via `client.Chat` (`ChatClient`). diff --git a/xdks/csharp/reference/clients/communities.mdx b/xdks/csharp/reference/clients/communities.mdx index 58e8f8415..4988546fe 100644 --- a/xdks/csharp/reference/clients/communities.mdx +++ b/xdks/csharp/reference/clients/communities.mdx @@ -1,7 +1,7 @@ --- -title: "CommunitiesClient (C# XDK)" +title: "CommunitiesClient" sidebarTitle: "Communities" -description: "C# XDK CommunitiesClient reference — 2 methods for X API v2 Communities endpoints." +description: "Methods for X API v2 Communities endpoints." --- Access **Communities** endpoints via `client.Communities` (`CommunitiesClient`). diff --git a/xdks/csharp/reference/clients/community-notes.mdx b/xdks/csharp/reference/clients/community-notes.mdx index fdbded4a8..024104997 100644 --- a/xdks/csharp/reference/clients/community-notes.mdx +++ b/xdks/csharp/reference/clients/community-notes.mdx @@ -1,7 +1,7 @@ --- -title: "CommunityNotesClient (C# XDK)" +title: "CommunityNotesClient" sidebarTitle: "Community Notes" -description: "C# XDK CommunityNotesClient reference — 5 methods for X API v2 Community Notes endpoints." +description: "Methods for X API v2 Community Notes endpoints." --- Access **Community Notes** endpoints via `client.CommunityNotes` (`CommunityNotesClient`). diff --git a/xdks/csharp/reference/clients/compliance.mdx b/xdks/csharp/reference/clients/compliance.mdx index 23fd4bc98..22a220396 100644 --- a/xdks/csharp/reference/clients/compliance.mdx +++ b/xdks/csharp/reference/clients/compliance.mdx @@ -1,7 +1,7 @@ --- -title: "ComplianceClient (C# XDK)" +title: "ComplianceClient" sidebarTitle: "Compliance" -description: "C# XDK ComplianceClient reference — 6 methods for X API v2 Compliance endpoints." +description: "Methods for X API v2 Compliance endpoints." --- Access **Compliance** endpoints via `client.Compliance` (`ComplianceClient`). diff --git a/xdks/csharp/reference/clients/connections.mdx b/xdks/csharp/reference/clients/connections.mdx index 0c0c48533..4ac7156ac 100644 --- a/xdks/csharp/reference/clients/connections.mdx +++ b/xdks/csharp/reference/clients/connections.mdx @@ -1,7 +1,7 @@ --- -title: "ConnectionsClient (C# XDK)" +title: "ConnectionsClient" sidebarTitle: "Connections" -description: "C# XDK ConnectionsClient reference — 4 methods for X API v2 Connections endpoints." +description: "Methods for X API v2 Connections endpoints." --- Access **Connections** endpoints via `client.Connections` (`ConnectionsClient`). diff --git a/xdks/csharp/reference/clients/direct-messages.mdx b/xdks/csharp/reference/clients/direct-messages.mdx index 41ed0265b..7bc459a03 100644 --- a/xdks/csharp/reference/clients/direct-messages.mdx +++ b/xdks/csharp/reference/clients/direct-messages.mdx @@ -1,7 +1,7 @@ --- -title: "DirectMessagesClient (C# XDK)" +title: "DirectMessagesClient" sidebarTitle: "Direct Messages" -description: "C# XDK DirectMessagesClient reference — 9 methods for X API v2 Direct Messages endpoints." +description: "Methods for X API v2 Direct Messages endpoints." --- Access **Direct Messages** endpoints via `client.DirectMessages` (`DirectMessagesClient`). diff --git a/xdks/csharp/reference/clients/general.mdx b/xdks/csharp/reference/clients/general.mdx index 404973994..7654e4b01 100644 --- a/xdks/csharp/reference/clients/general.mdx +++ b/xdks/csharp/reference/clients/general.mdx @@ -1,7 +1,7 @@ --- -title: "GeneralClient (C# XDK)" +title: "GeneralClient" sidebarTitle: "General" -description: "C# XDK GeneralClient reference — 1 methods for X API v2 General endpoints." +description: "Methods for X API v2 General endpoints." --- Access **General** endpoints via `client.General` (`GeneralClient`). diff --git a/xdks/csharp/reference/clients/lists.mdx b/xdks/csharp/reference/clients/lists.mdx index 768b22f72..9a96b0ba9 100644 --- a/xdks/csharp/reference/clients/lists.mdx +++ b/xdks/csharp/reference/clients/lists.mdx @@ -1,7 +1,7 @@ --- -title: "ListsClient (C# XDK)" +title: "ListsClient" sidebarTitle: "Lists" -description: "C# XDK ListsClient reference — 9 methods for X API v2 Lists endpoints." +description: "Methods for X API v2 Lists endpoints." --- Access **Lists** endpoints via `client.Lists` (`ListsClient`). diff --git a/xdks/csharp/reference/clients/media.mdx b/xdks/csharp/reference/clients/media.mdx index f46a05005..87e275d03 100644 --- a/xdks/csharp/reference/clients/media.mdx +++ b/xdks/csharp/reference/clients/media.mdx @@ -1,7 +1,7 @@ --- -title: "MediaClient (C# XDK)" +title: "MediaClient" sidebarTitle: "Media" -description: "C# XDK MediaClient reference — 19 methods for X API v2 Media endpoints." +description: "Methods for X API v2 Media endpoints." --- Access **Media** endpoints via `client.Media` (`MediaClient`). diff --git a/xdks/csharp/reference/clients/news.mdx b/xdks/csharp/reference/clients/news.mdx index 2f6708a32..b66d70482 100644 --- a/xdks/csharp/reference/clients/news.mdx +++ b/xdks/csharp/reference/clients/news.mdx @@ -1,7 +1,7 @@ --- -title: "NewsClient (C# XDK)" +title: "NewsClient" sidebarTitle: "News" -description: "C# XDK NewsClient reference — 2 methods for X API v2 News endpoints." +description: "Methods for X API v2 News endpoints." --- Access **News** endpoints via `client.News` (`NewsClient`). diff --git a/xdks/csharp/reference/clients/posts.mdx b/xdks/csharp/reference/clients/posts.mdx index 9e1130a6d..9bd0dbcfc 100644 --- a/xdks/csharp/reference/clients/posts.mdx +++ b/xdks/csharp/reference/clients/posts.mdx @@ -1,7 +1,7 @@ --- -title: "PostsClient (C# XDK)" +title: "PostsClient" sidebarTitle: "Posts" -description: "C# XDK PostsClient reference — 17 methods for X API v2 Posts endpoints." +description: "Methods for X API v2 Posts endpoints." --- Access **Posts** endpoints via `client.Posts` (`PostsClient`). diff --git a/xdks/csharp/reference/clients/spaces.mdx b/xdks/csharp/reference/clients/spaces.mdx index 94ef49b46..7cbb6c20a 100644 --- a/xdks/csharp/reference/clients/spaces.mdx +++ b/xdks/csharp/reference/clients/spaces.mdx @@ -1,7 +1,7 @@ --- -title: "SpacesClient (C# XDK)" +title: "SpacesClient" sidebarTitle: "Spaces" -description: "C# XDK SpacesClient reference — 6 methods for X API v2 Spaces endpoints." +description: "Methods for X API v2 Spaces endpoints." --- Access **Spaces** endpoints via `client.Spaces` (`SpacesClient`). diff --git a/xdks/csharp/reference/clients/stream.mdx b/xdks/csharp/reference/clients/stream.mdx index d2580d743..69e015326 100644 --- a/xdks/csharp/reference/clients/stream.mdx +++ b/xdks/csharp/reference/clients/stream.mdx @@ -1,7 +1,7 @@ --- -title: "StreamClient (C# XDK)" +title: "StreamClient" sidebarTitle: "Stream" -description: "C# XDK StreamClient reference — 18 methods for X API v2 Stream endpoints." +description: "Methods for X API v2 Stream endpoints." --- Access **Stream** endpoints via `client.Stream` (`StreamClient`). diff --git a/xdks/csharp/reference/clients/trends.mdx b/xdks/csharp/reference/clients/trends.mdx index f54a36e20..1c3ccdd12 100644 --- a/xdks/csharp/reference/clients/trends.mdx +++ b/xdks/csharp/reference/clients/trends.mdx @@ -1,7 +1,7 @@ --- -title: "TrendsClient (C# XDK)" +title: "TrendsClient" sidebarTitle: "Trends" -description: "C# XDK TrendsClient reference — 3 methods for X API v2 Trends endpoints." +description: "Methods for X API v2 Trends endpoints." --- Access **Trends** endpoints via `client.Trends` (`TrendsClient`). diff --git a/xdks/csharp/reference/clients/usage.mdx b/xdks/csharp/reference/clients/usage.mdx index 9a64b7474..0b1078840 100644 --- a/xdks/csharp/reference/clients/usage.mdx +++ b/xdks/csharp/reference/clients/usage.mdx @@ -1,7 +1,7 @@ --- -title: "UsageClient (C# XDK)" +title: "UsageClient" sidebarTitle: "Usage" -description: "C# XDK UsageClient reference — 2 methods for X API v2 Usage endpoints." +description: "Methods for X API v2 Usage endpoints." --- Access **Usage** endpoints via `client.Usage` (`UsageClient`). diff --git a/xdks/csharp/reference/clients/users.mdx b/xdks/csharp/reference/clients/users.mdx index a937dd928..9ab041205 100644 --- a/xdks/csharp/reference/clients/users.mdx +++ b/xdks/csharp/reference/clients/users.mdx @@ -1,7 +1,7 @@ --- -title: "UsersClient (C# XDK)" +title: "UsersClient" sidebarTitle: "Users" -description: "C# XDK UsersClient reference — 46 methods for X API v2 Users endpoints." +description: "Methods for X API v2 Users endpoints." --- Access **Users** endpoints via `client.Users` (`UsersClient`). diff --git a/xdks/csharp/reference/clients/webhooks.mdx b/xdks/csharp/reference/clients/webhooks.mdx index c86bff426..5a841764a 100644 --- a/xdks/csharp/reference/clients/webhooks.mdx +++ b/xdks/csharp/reference/clients/webhooks.mdx @@ -1,7 +1,7 @@ --- -title: "WebhooksClient (C# XDK)" +title: "WebhooksClient" sidebarTitle: "Webhooks" -description: "C# XDK WebhooksClient reference — 8 methods for X API v2 Webhooks endpoints." +description: "Methods for X API v2 Webhooks endpoints." --- Access **Webhooks** endpoints via `client.Webhooks` (`WebhooksClient`). diff --git a/xdks/csharp/reference/overview.mdx b/xdks/csharp/reference/overview.mdx index c3a684e68..2fb581f92 100644 --- a/xdks/csharp/reference/overview.mdx +++ b/xdks/csharp/reference/overview.mdx @@ -1,17 +1,17 @@ --- -title: "C# XDK API Reference" +title: "API Reference" sidebarTitle: "Overview" -description: "Complete API reference for the official C# XDK (XDevPlatform.Xdk v0.1.2) across all X API v2 resource clients." +description: "Client and method reference for the C# XDK (XDevPlatform.Xdk v0.1.2)." --- -The official **C# XDK** (`XDevPlatform.Xdk`, `v0.1.2`) provides typed resource clients, authentication helpers, automatic pagination, and real-time streaming for the X API v2. +Client setup and method reference for `XDevPlatform.Xdk` `v0.1.2`. - - Install `XDevPlatform.Xdk` (`v0.1.2`) — requires .NET 8.0+. + + `XDevPlatform.Xdk` `v0.1.2` · .NET 8.0+ - - Source code, release notes, and issue tracker for `XDevPlatform.Xdk`. + + Source code and issues. @@ -49,7 +49,7 @@ using var client = new XClient(new XClientOptions Base URL for X API requests (`XClient` implements `IDisposable`). -## Resource Clients +## Clients | Resource | Accessor | Client Class | Operations | | :--- | :--- | :--- | ---: | diff --git a/xdks/csharp/streaming.mdx b/xdks/csharp/streaming.mdx index c633fdfd6..13280fdd2 100644 --- a/xdks/csharp/streaming.mdx +++ b/xdks/csharp/streaming.mdx @@ -1,12 +1,12 @@ --- -title: C# Streaming +title: Streaming sidebarTitle: Streaming -description: Consume real-time X API v2 streams in C# using EventStream (IAsyncEnumerable and IAsyncDisposable) with automatic reconnection. +description: Consume real-time X API v2 streams and manage filtered stream rules in C#. --- -Streaming endpoints on `client.Stream` return `EventStream`, which implements both `IAsyncEnumerable` and `IAsyncDisposable`. Use `await using` together with `await foreach` to consume events in real time and release the HTTP connection cleanly when done. +Streaming methods on `client.Stream` return `EventStream` (`IAsyncEnumerable` and `IAsyncDisposable`). Use `await using` with `await foreach` so the HTTP connection closes when you exit the loop. -## Consuming Filtered & Sampled Streams +## Filtered and sampled streams ```csharp using System; @@ -38,9 +38,7 @@ await foreach (var item in stream.WithCancellation(cts.Token)) } ``` -## Managing Filtered Stream Rules - -Add or remove rules using `client.Stream.UpdateRulesAsync(...)` and inspect active rules with `client.Stream.GetRulesPages()`: +## Managing rules ```csharp using System.Text.Json; @@ -56,4 +54,4 @@ await foreach (var page in client.Stream.GetRulesPages()) } ``` -See [Build a Rule](/x-api/posts/filtered-stream/integrate/build-a-rule) for the full Filtered Stream operator reference. +See [Build a Rule](/x-api/posts/filtered-stream/integrate/build-a-rule) for rule syntax and operators. diff --git a/xdks/java/authentication.mdx b/xdks/java/authentication.mdx index da24dd9d2..17d53cc0d 100644 --- a/xdks/java/authentication.mdx +++ b/xdks/java/authentication.mdx @@ -1,16 +1,12 @@ --- -title: Java Authentication +title: Authentication sidebarTitle: Authentication -description: Authenticate the Java XDK (com.x:xdk) using Bearer Tokens, OAuth 2.0 PKCE with token refresh, or OAuth 1.0a user context. +description: Configure Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a in the Java XDK. --- -`XClient` supports all three X API v2 authentication modes: +`XClient` supports Bearer Token (app-only), OAuth 2.0 with PKCE (user context), and OAuth 1.0a (user context). Get your credentials from the [X Developer Console](https://console.x.com). -1. **Bearer Token (App-Only)** — Public read, search, and filtered/sample streaming endpoints. -2. **OAuth 2.0 User Context with PKCE** — Scoped user-authorized calls (`POST /2/tweets`, bookmarks, DMs, X Chat) with refresh token support. -3. **OAuth 1.0a User Context** — HMAC-SHA1 request signing. - -## 1. Bearer Token (App-Only) +## Bearer Token ```java import com.x.xdk.XClient; @@ -22,9 +18,9 @@ XClient client = XClient.builder() var user = client.users().getByUsername("XDevelopers"); ``` -## 2. OAuth 2.0 User Context with PKCE +## OAuth 2.0 with PKCE -If you already hold an OAuth 2.0 user access token: +If you already have a user access token: ```java XClient client = XClient.builder() @@ -34,7 +30,7 @@ XClient client = XClient.builder() var me = client.users().getMe(); ``` -To run the full RFC 7636 PKCE authorization flow and enable token refresh via `OAuth2Pkce`: +To run the PKCE authorization flow and refresh tokens with `OAuth2Pkce`: ```java import com.x.xdk.Schemas; @@ -50,13 +46,13 @@ OAuth2Pkce oauth2 = new OAuth2Pkce( List.of("tweet.read", "tweet.write", "users.read", "offline.access") ); -// 1. Redirect the user to authorize your app +// 1. Direct the user to authorize your app String authorizationUrl = oauth2.getAuthorizationUrl("random-csrf-state"); // 2. Exchange the callback `code` parameter for tokens OAuth2Token token = oauth2.exchangeCode(callbackCode); -// 3. Build XClient attached to the OAuth2Pkce manager +// 3. Build XClient with the OAuth2Pkce instance XClient client = XClient.builder() .oauth2(oauth2) .build(); @@ -65,11 +61,11 @@ Schemas.CreatePostsResponse created = client.posts().create( new Schemas.CreatePostsRequest().text("Hello from Java XDK!") ); -// Refresh tokens explicitly when needed (requires offline.access scope) +// Refresh tokens when needed (requires offline.access scope) client.refreshToken(); ``` -## 3. OAuth 1.0a User Context +## OAuth 1.0a ```java import com.x.xdk.Schemas; @@ -90,3 +86,5 @@ XClient client = XClient.builder() Schemas.GetUsersMeResponse me = client.users().getMe(); ``` + +See the [Java samples repo](https://github.com/xdevplatform/samples/tree/main/java) for more examples. diff --git a/xdks/java/install.mdx b/xdks/java/install.mdx index 6e28b1406..8e49e950d 100644 --- a/xdks/java/install.mdx +++ b/xdks/java/install.mdx @@ -1,17 +1,10 @@ --- -title: Install Java XDK +title: Install sidebarTitle: Install -description: Add the official Java XDK (com.x:xdk) to your Maven or Gradle project for Java 17+ and Kotlin. +description: Add the Java XDK to a Maven or Gradle project. --- -Install `com.x:xdk` from [Maven Central](https://central.sonatype.com/artifact/com.x/xdk). - -## Prerequisites - -- **JDK 17+** (tested on JDK 17 and JDK 21) -- Maven 3.8+ or Gradle 8+ - -## Add Dependency +Install `com.x:xdk` from [Maven Central](https://central.sonatype.com/artifact/com.x/xdk). Requires JDK 17+. @@ -37,7 +30,7 @@ dependencies { -## Build from Source +## Build from source ```bash git clone https://github.com/xdevplatform/xdk-java.git @@ -45,8 +38,8 @@ cd xdk-java mvn test ``` -## Next Steps +## Next steps -- [Quickstart](/xdks/java/quickstart) — Make your first request -- [Authentication](/xdks/java/authentication) — Configure Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a -- [API Reference](/xdks/java/reference/overview) — Explore all 24 resource clients +- [Quickstart](/xdks/java/quickstart) +- [Authentication](/xdks/java/authentication) +- [API Reference](/xdks/java/reference/overview) diff --git a/xdks/java/llms.txt b/xdks/java/llms.txt index 3677f45f5..4670715b6 100644 --- a/xdks/java/llms.txt +++ b/xdks/java/llms.txt @@ -1,19 +1,19 @@ # Java XDK (`com.x:xdk` v0.1.2) -> Official Java SDK for the X API v2 (Java 17+). Install with `implementation("com.x:xdk:0.1.2")`. +> Official Java client library for the X API v2 (Java 17+). Install with `implementation("com.x:xdk:0.1.2")`. ## Guides -- [Java overview](https://docs.x.com/xdks/java/overview.md): Architecture, capabilities, and client overview -- [Java install](https://docs.x.com/xdks/java/install.md): Package installation and runtime requirements -- [Java quickstart](https://docs.x.com/xdks/java/quickstart.md): First authenticated X API v2 request in under 2 minutes -- [Java authentication](https://docs.x.com/xdks/java/authentication.md): Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a user-context setup -- [Java pagination](https://docs.x.com/xdks/java/pagination.md): Automatic cursor iteration across multi-page endpoints -- [Java streaming](https://docs.x.com/xdks/java/streaming.md): Real-time event streams with reconnection and lifecycle handling +- [Java overview](https://docs.x.com/xdks/java/overview.md): Overview and quick example +- [Java install](https://docs.x.com/xdks/java/install.md): Installation and requirements +- [Java quickstart](https://docs.x.com/xdks/java/quickstart.md): Make your first X API v2 request +- [Java authentication](https://docs.x.com/xdks/java/authentication.md): Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a +- [Java pagination](https://docs.x.com/xdks/java/pagination.md): Cursor pagination across multi-page endpoints +- [Java streaming](https://docs.x.com/xdks/java/streaming.md): Real-time event streams and filtered stream rules ## Client Reference -- [Reference Overview](https://docs.x.com/xdks/java/reference/overview.md): Main client options and resource client directory +- [Reference Overview](https://docs.x.com/xdks/java/reference/overview.md): Client options and client list - [`AccountClient` (Account)](https://docs.x.com/xdks/java/reference/clients/account.md): 2 methods via `client.account()` - [`AccountActivityClient` (Account Activity)](https://docs.x.com/xdks/java/reference/clients/account-activity.md): 5 methods via `client.accountActivity()` - [`ActivityClient` (Activity)](https://docs.x.com/xdks/java/reference/clients/activity.md): 5 methods via `client.activity()` diff --git a/xdks/java/overview.mdx b/xdks/java/overview.mdx index 60c73953d..354621f4f 100644 --- a/xdks/java/overview.mdx +++ b/xdks/java/overview.mdx @@ -1,29 +1,21 @@ --- title: Java XDK sidebarTitle: Overview -description: Official Java SDK (com.x:xdk) for the X API v2 targeting Java 17+, Kotlin, and JVM services with fluent builders, OAuth 2.0 PKCE, Paginator, and EventStream. +description: Java client library for the X API v2. --- -The **Java XDK** (`com.x:xdk`) is X's official JVM client library for the X API v2, generated directly from the [official OpenAPI specification](https://api.x.com/2/openapi.json) and published to Maven Central. +`com.x:xdk` is the official Java SDK for the X API v2 (Java 17+ and Kotlin). It includes typed models, OAuth 2.0 PKCE and OAuth 1.0a auth, `Paginator`, and `EventStream`. - `com.x:xdk:0.1.2` — Java 17+. + `com.x:xdk:0.1.2` · Java 17+ - - Source code, runnable examples, and issue tracker. + + Source code and issues. -## Key Features - -- **Modern JVM Design**: Built on `java.net.http.HttpClient` and Jackson (`com.fasterxml.jackson`) for Java 17+, Java 21 virtual threads, Kotlin, and Scala. -- **Fluent Builders**: Configure `XClient.builder()`, typed request models (`new Schemas.CreatePostsRequest().text("...")`), and per-endpoint `*Options.builder()`. -- **Authentication**: App-only Bearer Token, OAuth 2.0 User Context with PKCE (`OAuth2Pkce`) and automatic refresh, and OAuth 1.0a HMAC-SHA1 (`OAuth1`). -- **Lazy Cursor Pagination**: Every paginated operation exposes a `*Pages(...)` method returning `Paginator` (`Iterable`). -- **Resilient Streaming**: Streaming endpoints return `EventStream` (`Iterable` & `AutoCloseable`) with incremental UTF-8 line framing and exponential backoff reconnection. - -## Quick Example +## Quick example ```java import com.x.xdk.Schemas; @@ -47,25 +39,25 @@ public class Example { } ``` -## Guides & Reference +## Guides Add `com.x:xdk` with Maven or Gradle. - Make your first X API v2 request in Java. + Make your first request. - Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a setup. + Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a. - Iterate pages lazily with `Paginator`. + Iterate pages with `Paginator`. - Consume live NDJSON streams with `EventStream`. + Read live streams with `EventStream`. - - Full method & parameter reference for all 24 clients. + + Methods and parameters for each client. diff --git a/xdks/java/pagination.mdx b/xdks/java/pagination.mdx index c60e8321a..af93b99cb 100644 --- a/xdks/java/pagination.mdx +++ b/xdks/java/pagination.mdx @@ -1,12 +1,12 @@ --- -title: Java Pagination +title: Pagination sidebarTitle: Pagination -description: Automatically iterate paginated X API v2 endpoints in Java using Paginator and *Pages(...) methods. +description: Paginate X API v2 responses in Java with Paginator or manual tokens. --- -Every paginated endpoint in the Java XDK exposes a companion `*Pages(...)` method returning `Paginator` (`Iterable`), which lazily fetches subsequent pages using `meta.next_token` as you iterate. +Paginated endpoints expose a `*Pages(...)` method returning `Paginator` (`Iterable`), which fetches pages lazily using `meta.next_token`. -## Automatic Pagination (`*Pages`) +## Automatic pagination (`*Pages`) ```java import com.x.xdk.Paginator; @@ -33,14 +33,14 @@ for (Schemas.SearchPostsRecentResponse page : pages) { System.out.println("Fetched " + page.getData().size() + " posts"); } if (++pageCount >= 5) { - break; // Stop early at any point; no extra HTTP requests are made + break; // Stop early without extra requests } } ``` -## Manual Cursor Control +## Manual pagination -If you prefer to store and pass cursors across stateless HTTP requests, call the single-page method directly with `.paginationToken(...)`: +Call the single-page method directly with `.paginationToken(...)`: ```java Schemas.SearchPostsRecentResponse firstPage = client.posts().searchRecent( diff --git a/xdks/java/quickstart.mdx b/xdks/java/quickstart.mdx index 14b49ac20..8b8178dda 100644 --- a/xdks/java/quickstart.mdx +++ b/xdks/java/quickstart.mdx @@ -1,13 +1,11 @@ --- -title: Java Quickstart +title: Quickstart sidebarTitle: Quickstart -description: Make your first X API v2 request in Java using com.x:xdk and an app-only Bearer Token. +description: Make your first X API v2 request with the Java XDK. --- -Make your first authenticated X API v2 call with `com.x:xdk` in minutes. - - + ```xml com.x @@ -17,13 +15,13 @@ Make your first authenticated X API v2 call with `com.x:xdk` in minutes. ``` - Generate a **Bearer Token** in the [X Developer Console](https://console.x.com) and set it in your environment: + Generate a **Bearer Token** in the [X Developer Console](https://console.x.com) and set it in your shell: ```bash export X_BEARER_TOKEN="your_bearer_token_here" ``` - + ```java import com.x.xdk.Schemas; import com.x.xdk.XClient; @@ -53,9 +51,9 @@ public class Quickstart { -## Next Steps +## Next steps -- [Authentication](/xdks/java/authentication) — Act on behalf of users with OAuth 2.0 PKCE or OAuth 1.0a -- [Pagination](/xdks/java/pagination) — Iterate multi-page results with `Paginator` -- [Streaming](/xdks/java/streaming) — Subscribe to live streams with `EventStream` -- [Client Reference](/xdks/java/reference/overview) — Browse all 24 resource clients +- [Authentication](/xdks/java/authentication) — Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a +- [Pagination](/xdks/java/pagination) — Iterate pages with `Paginator` +- [Streaming](/xdks/java/streaming) — Read live streams with `EventStream` +- [Code samples](https://github.com/xdevplatform/samples/tree/main/java) — Runnable Java examples diff --git a/xdks/java/reference/clients/account-activity.mdx b/xdks/java/reference/clients/account-activity.mdx index cb9336f1b..c1081420c 100644 --- a/xdks/java/reference/clients/account-activity.mdx +++ b/xdks/java/reference/clients/account-activity.mdx @@ -1,7 +1,7 @@ --- -title: "AccountActivityClient (Java XDK)" +title: "AccountActivityClient" sidebarTitle: "Account Activity" -description: "Java XDK AccountActivityClient reference — 5 methods for X API v2 Account Activity endpoints." +description: "Methods for X API v2 Account Activity endpoints." --- Access **Account Activity** endpoints via `client.accountActivity()` (`AccountActivityClient`). diff --git a/xdks/java/reference/clients/account.mdx b/xdks/java/reference/clients/account.mdx index fe76f05d2..baef2c052 100644 --- a/xdks/java/reference/clients/account.mdx +++ b/xdks/java/reference/clients/account.mdx @@ -1,7 +1,7 @@ --- -title: "AccountClient (Java XDK)" +title: "AccountClient" sidebarTitle: "Account" -description: "Java XDK AccountClient reference — 2 methods for X API v2 Account endpoints." +description: "Methods for X API v2 Account endpoints." --- Access **Account** endpoints via `client.account()` (`AccountClient`). diff --git a/xdks/java/reference/clients/activity.mdx b/xdks/java/reference/clients/activity.mdx index 47a59a20b..211fa6a41 100644 --- a/xdks/java/reference/clients/activity.mdx +++ b/xdks/java/reference/clients/activity.mdx @@ -1,7 +1,7 @@ --- -title: "ActivityClient (Java XDK)" +title: "ActivityClient" sidebarTitle: "Activity" -description: "Java XDK ActivityClient reference — 5 methods for X API v2 Activity endpoints." +description: "Methods for X API v2 Activity endpoints." --- Access **Activity** endpoints via `client.activity()` (`ActivityClient`). diff --git a/xdks/java/reference/clients/articles.mdx b/xdks/java/reference/clients/articles.mdx index fe561f288..196b86c7e 100644 --- a/xdks/java/reference/clients/articles.mdx +++ b/xdks/java/reference/clients/articles.mdx @@ -1,7 +1,7 @@ --- -title: "ArticlesClient (Java XDK)" +title: "ArticlesClient" sidebarTitle: "Articles" -description: "Java XDK ArticlesClient reference — 2 methods for X API v2 Articles endpoints." +description: "Methods for X API v2 Articles endpoints." --- Access **Articles** endpoints via `client.articles()` (`ArticlesClient`). diff --git a/xdks/java/reference/clients/bots.mdx b/xdks/java/reference/clients/bots.mdx index 881fa9b86..4f9d5ba7e 100644 --- a/xdks/java/reference/clients/bots.mdx +++ b/xdks/java/reference/clients/bots.mdx @@ -1,7 +1,7 @@ --- -title: "BotsClient (Java XDK)" +title: "BotsClient" sidebarTitle: "Bots" -description: "Java XDK BotsClient reference — 6 methods for X API v2 Bots endpoints." +description: "Methods for X API v2 Bots endpoints." --- Access **Bots** endpoints via `client.bots()` (`BotsClient`). diff --git a/xdks/java/reference/clients/broadcasts.mdx b/xdks/java/reference/clients/broadcasts.mdx index 68c3156fe..6f3b4aa94 100644 --- a/xdks/java/reference/clients/broadcasts.mdx +++ b/xdks/java/reference/clients/broadcasts.mdx @@ -1,7 +1,7 @@ --- -title: "BroadcastsClient (Java XDK)" +title: "BroadcastsClient" sidebarTitle: "Broadcasts" -description: "Java XDK BroadcastsClient reference — 41 methods for X API v2 Broadcasts endpoints." +description: "Methods for X API v2 Broadcasts endpoints." --- Access **Broadcasts** endpoints via `client.broadcasts()` (`BroadcastsClient`). diff --git a/xdks/java/reference/clients/calls.mdx b/xdks/java/reference/clients/calls.mdx index 707beb5a8..260d67c87 100644 --- a/xdks/java/reference/clients/calls.mdx +++ b/xdks/java/reference/clients/calls.mdx @@ -1,7 +1,7 @@ --- -title: "CallsClient (Java XDK)" +title: "CallsClient" sidebarTitle: "Calls" -description: "Java XDK CallsClient reference — 10 methods for X API v2 Calls endpoints." +description: "Methods for X API v2 Calls endpoints." --- Access **Calls** endpoints via `client.calls()` (`CallsClient`). diff --git a/xdks/java/reference/clients/chat.mdx b/xdks/java/reference/clients/chat.mdx index de3d05b85..e5fb66a6a 100644 --- a/xdks/java/reference/clients/chat.mdx +++ b/xdks/java/reference/clients/chat.mdx @@ -1,7 +1,7 @@ --- -title: "ChatClient (Java XDK)" +title: "ChatClient" sidebarTitle: "Chat" -description: "Java XDK ChatClient reference — 45 methods for X API v2 Chat endpoints." +description: "Methods for X API v2 Chat endpoints." --- Access **Chat** endpoints via `client.chat()` (`ChatClient`). diff --git a/xdks/java/reference/clients/communities.mdx b/xdks/java/reference/clients/communities.mdx index 2557d6bc9..f9819eca9 100644 --- a/xdks/java/reference/clients/communities.mdx +++ b/xdks/java/reference/clients/communities.mdx @@ -1,7 +1,7 @@ --- -title: "CommunitiesClient (Java XDK)" +title: "CommunitiesClient" sidebarTitle: "Communities" -description: "Java XDK CommunitiesClient reference — 2 methods for X API v2 Communities endpoints." +description: "Methods for X API v2 Communities endpoints." --- Access **Communities** endpoints via `client.communities()` (`CommunitiesClient`). diff --git a/xdks/java/reference/clients/community-notes.mdx b/xdks/java/reference/clients/community-notes.mdx index 2880b050b..176a114c1 100644 --- a/xdks/java/reference/clients/community-notes.mdx +++ b/xdks/java/reference/clients/community-notes.mdx @@ -1,7 +1,7 @@ --- -title: "CommunityNotesClient (Java XDK)" +title: "CommunityNotesClient" sidebarTitle: "Community Notes" -description: "Java XDK CommunityNotesClient reference — 5 methods for X API v2 Community Notes endpoints." +description: "Methods for X API v2 Community Notes endpoints." --- Access **Community Notes** endpoints via `client.communityNotes()` (`CommunityNotesClient`). diff --git a/xdks/java/reference/clients/compliance.mdx b/xdks/java/reference/clients/compliance.mdx index 54e8d6f80..7e7ba9415 100644 --- a/xdks/java/reference/clients/compliance.mdx +++ b/xdks/java/reference/clients/compliance.mdx @@ -1,7 +1,7 @@ --- -title: "ComplianceClient (Java XDK)" +title: "ComplianceClient" sidebarTitle: "Compliance" -description: "Java XDK ComplianceClient reference — 6 methods for X API v2 Compliance endpoints." +description: "Methods for X API v2 Compliance endpoints." --- Access **Compliance** endpoints via `client.compliance()` (`ComplianceClient`). diff --git a/xdks/java/reference/clients/connections.mdx b/xdks/java/reference/clients/connections.mdx index 05e1a5698..e90a80b85 100644 --- a/xdks/java/reference/clients/connections.mdx +++ b/xdks/java/reference/clients/connections.mdx @@ -1,7 +1,7 @@ --- -title: "ConnectionsClient (Java XDK)" +title: "ConnectionsClient" sidebarTitle: "Connections" -description: "Java XDK ConnectionsClient reference — 4 methods for X API v2 Connections endpoints." +description: "Methods for X API v2 Connections endpoints." --- Access **Connections** endpoints via `client.connections()` (`ConnectionsClient`). diff --git a/xdks/java/reference/clients/direct-messages.mdx b/xdks/java/reference/clients/direct-messages.mdx index ec000412c..633755d9e 100644 --- a/xdks/java/reference/clients/direct-messages.mdx +++ b/xdks/java/reference/clients/direct-messages.mdx @@ -1,7 +1,7 @@ --- -title: "DirectMessagesClient (Java XDK)" +title: "DirectMessagesClient" sidebarTitle: "Direct Messages" -description: "Java XDK DirectMessagesClient reference — 9 methods for X API v2 Direct Messages endpoints." +description: "Methods for X API v2 Direct Messages endpoints." --- Access **Direct Messages** endpoints via `client.directMessages()` (`DirectMessagesClient`). diff --git a/xdks/java/reference/clients/general.mdx b/xdks/java/reference/clients/general.mdx index 57ce4004a..c894aebd7 100644 --- a/xdks/java/reference/clients/general.mdx +++ b/xdks/java/reference/clients/general.mdx @@ -1,7 +1,7 @@ --- -title: "GeneralClient (Java XDK)" +title: "GeneralClient" sidebarTitle: "General" -description: "Java XDK GeneralClient reference — 1 methods for X API v2 General endpoints." +description: "Methods for X API v2 General endpoints." --- Access **General** endpoints via `client.general()` (`GeneralClient`). diff --git a/xdks/java/reference/clients/lists.mdx b/xdks/java/reference/clients/lists.mdx index 954a76c80..2d63830a7 100644 --- a/xdks/java/reference/clients/lists.mdx +++ b/xdks/java/reference/clients/lists.mdx @@ -1,7 +1,7 @@ --- -title: "ListsClient (Java XDK)" +title: "ListsClient" sidebarTitle: "Lists" -description: "Java XDK ListsClient reference — 9 methods for X API v2 Lists endpoints." +description: "Methods for X API v2 Lists endpoints." --- Access **Lists** endpoints via `client.lists()` (`ListsClient`). diff --git a/xdks/java/reference/clients/media.mdx b/xdks/java/reference/clients/media.mdx index cc6c9f63e..06745b0a3 100644 --- a/xdks/java/reference/clients/media.mdx +++ b/xdks/java/reference/clients/media.mdx @@ -1,7 +1,7 @@ --- -title: "MediaClient (Java XDK)" +title: "MediaClient" sidebarTitle: "Media" -description: "Java XDK MediaClient reference — 19 methods for X API v2 Media endpoints." +description: "Methods for X API v2 Media endpoints." --- Access **Media** endpoints via `client.media()` (`MediaClient`). diff --git a/xdks/java/reference/clients/news.mdx b/xdks/java/reference/clients/news.mdx index 7e2c41405..22e0c6e7b 100644 --- a/xdks/java/reference/clients/news.mdx +++ b/xdks/java/reference/clients/news.mdx @@ -1,7 +1,7 @@ --- -title: "NewsClient (Java XDK)" +title: "NewsClient" sidebarTitle: "News" -description: "Java XDK NewsClient reference — 2 methods for X API v2 News endpoints." +description: "Methods for X API v2 News endpoints." --- Access **News** endpoints via `client.news()` (`NewsClient`). diff --git a/xdks/java/reference/clients/posts.mdx b/xdks/java/reference/clients/posts.mdx index d26f24c34..eb0f7fe59 100644 --- a/xdks/java/reference/clients/posts.mdx +++ b/xdks/java/reference/clients/posts.mdx @@ -1,7 +1,7 @@ --- -title: "PostsClient (Java XDK)" +title: "PostsClient" sidebarTitle: "Posts" -description: "Java XDK PostsClient reference — 17 methods for X API v2 Posts endpoints." +description: "Methods for X API v2 Posts endpoints." --- Access **Posts** endpoints via `client.posts()` (`PostsClient`). diff --git a/xdks/java/reference/clients/spaces.mdx b/xdks/java/reference/clients/spaces.mdx index 199ca945d..b778127a2 100644 --- a/xdks/java/reference/clients/spaces.mdx +++ b/xdks/java/reference/clients/spaces.mdx @@ -1,7 +1,7 @@ --- -title: "SpacesClient (Java XDK)" +title: "SpacesClient" sidebarTitle: "Spaces" -description: "Java XDK SpacesClient reference — 6 methods for X API v2 Spaces endpoints." +description: "Methods for X API v2 Spaces endpoints." --- Access **Spaces** endpoints via `client.spaces()` (`SpacesClient`). diff --git a/xdks/java/reference/clients/stream.mdx b/xdks/java/reference/clients/stream.mdx index 2c5853380..4a1c61f62 100644 --- a/xdks/java/reference/clients/stream.mdx +++ b/xdks/java/reference/clients/stream.mdx @@ -1,7 +1,7 @@ --- -title: "StreamClient (Java XDK)" +title: "StreamClient" sidebarTitle: "Stream" -description: "Java XDK StreamClient reference — 18 methods for X API v2 Stream endpoints." +description: "Methods for X API v2 Stream endpoints." --- Access **Stream** endpoints via `client.stream()` (`StreamClient`). diff --git a/xdks/java/reference/clients/trends.mdx b/xdks/java/reference/clients/trends.mdx index f733c8e91..7d06ab912 100644 --- a/xdks/java/reference/clients/trends.mdx +++ b/xdks/java/reference/clients/trends.mdx @@ -1,7 +1,7 @@ --- -title: "TrendsClient (Java XDK)" +title: "TrendsClient" sidebarTitle: "Trends" -description: "Java XDK TrendsClient reference — 3 methods for X API v2 Trends endpoints." +description: "Methods for X API v2 Trends endpoints." --- Access **Trends** endpoints via `client.trends()` (`TrendsClient`). diff --git a/xdks/java/reference/clients/usage.mdx b/xdks/java/reference/clients/usage.mdx index 6284446d4..b4f2bea9e 100644 --- a/xdks/java/reference/clients/usage.mdx +++ b/xdks/java/reference/clients/usage.mdx @@ -1,7 +1,7 @@ --- -title: "UsageClient (Java XDK)" +title: "UsageClient" sidebarTitle: "Usage" -description: "Java XDK UsageClient reference — 2 methods for X API v2 Usage endpoints." +description: "Methods for X API v2 Usage endpoints." --- Access **Usage** endpoints via `client.usage()` (`UsageClient`). diff --git a/xdks/java/reference/clients/users.mdx b/xdks/java/reference/clients/users.mdx index d2f8c7fb4..98265d472 100644 --- a/xdks/java/reference/clients/users.mdx +++ b/xdks/java/reference/clients/users.mdx @@ -1,7 +1,7 @@ --- -title: "UsersClient (Java XDK)" +title: "UsersClient" sidebarTitle: "Users" -description: "Java XDK UsersClient reference — 46 methods for X API v2 Users endpoints." +description: "Methods for X API v2 Users endpoints." --- Access **Users** endpoints via `client.users()` (`UsersClient`). diff --git a/xdks/java/reference/clients/webhooks.mdx b/xdks/java/reference/clients/webhooks.mdx index e8c3ea2b5..6b17a36d5 100644 --- a/xdks/java/reference/clients/webhooks.mdx +++ b/xdks/java/reference/clients/webhooks.mdx @@ -1,7 +1,7 @@ --- -title: "WebhooksClient (Java XDK)" +title: "WebhooksClient" sidebarTitle: "Webhooks" -description: "Java XDK WebhooksClient reference — 8 methods for X API v2 Webhooks endpoints." +description: "Methods for X API v2 Webhooks endpoints." --- Access **Webhooks** endpoints via `client.webhooks()` (`WebhooksClient`). diff --git a/xdks/java/reference/overview.mdx b/xdks/java/reference/overview.mdx index 190590e0d..3c8c65266 100644 --- a/xdks/java/reference/overview.mdx +++ b/xdks/java/reference/overview.mdx @@ -1,17 +1,17 @@ --- -title: "Java XDK API Reference" +title: "API Reference" sidebarTitle: "Overview" -description: "Complete API reference for the official Java XDK (com.x:xdk v0.1.2) across all X API v2 resource clients." +description: "Client and method reference for the Java XDK (com.x:xdk v0.1.2)." --- -The official **Java XDK** (`com.x:xdk`, `v0.1.2`) provides typed resource clients, authentication helpers, automatic pagination, and real-time streaming for the X API v2. +Client setup and method reference for `com.x:xdk` `v0.1.2`. - - Install `com.x:xdk` (`v0.1.2`) — requires Java 17+. + + `com.x:xdk` `v0.1.2` · Java 17+ - - Source code, release notes, and issue tracker for `com.x:xdk`. + + Source code and issues. @@ -47,7 +47,7 @@ XClient client = XClient.builder() Overrides the X API base URL. -## Resource Clients +## Clients | Resource | Accessor | Client Class | Operations | | :--- | :--- | :--- | ---: | diff --git a/xdks/java/streaming.mdx b/xdks/java/streaming.mdx index 1f543d0d1..19071e419 100644 --- a/xdks/java/streaming.mdx +++ b/xdks/java/streaming.mdx @@ -1,12 +1,12 @@ --- -title: Java Streaming +title: Streaming sidebarTitle: Streaming -description: Consume real-time X API v2 streams in Java using EventStream with try-with-resources lifecycle management and automatic reconnection. +description: Consume real-time X API v2 streams and manage filtered stream rules in Java. --- -Streaming methods on `client.stream()` return `EventStream`, which implements both `Iterable` and `AutoCloseable`. Wrapping the stream in `try (...)` guarantees the underlying HTTP connection is closed cleanly when you exit the loop. +Streaming methods on `client.stream()` return `EventStream` (`Iterable` and `AutoCloseable`). Use `try (...)` so the underlying HTTP connection closes when you exit the loop. -## Sampled & Filtered Post Streams +## Filtered and sampled streams ```java import com.x.xdk.Schemas; @@ -26,19 +26,16 @@ try (var stream = client.stream().posts(options)) { for (Schemas.StreamPostsResponse event : stream) { System.out.println(event.getData()); if (++count >= 25) { - break; // Exiting try-with-resources closes the HTTP stream + break; } } } ``` -## Managing Filtered Stream Rules - -Add or delete Filtered Stream rules via `client.stream().updateRules(...)` and inspect active rules with `client.stream().getRulesPages()`: +## Managing rules ```java import com.fasterxml.jackson.databind.ObjectMapper; -import com.x.xdk.XClient; ObjectMapper mapper = new ObjectMapper(); @@ -54,4 +51,4 @@ for (var page : client.stream().getRulesPages()) { } ``` -See [Build a Rule](/x-api/posts/filtered-stream/integrate/build-a-rule) for the full Filtered Stream operator reference. +See [Build a Rule](/x-api/posts/filtered-stream/integrate/build-a-rule) for rule syntax and operators. diff --git a/xdks/llms.txt b/xdks/llms.txt index 89faf5a8a..ae534ff3d 100644 --- a/xdks/llms.txt +++ b/xdks/llms.txt @@ -1,23 +1,23 @@ -# X Official SDKs (XDKs) +# XDKs -> Official, OpenAPI-generated client libraries for the X API v2 in Python, TypeScript, Java, and C# (.NET). +> Official client libraries for the X API v2 in Python, TypeScript, Java, and C#. -## Official Packages +## Packages - **Python**: `xdk` (`v0.11.2`, Python 3.8+) — `pip install xdk` — [Index](https://docs.x.com/xdks/python/llms.txt) - **TypeScript**: `@xdevplatform/xdk` (`v0.7.2`, Node.js 18+ (ESM & CommonJS)) — `npm install @xdevplatform/xdk` — [Index](https://docs.x.com/xdks/typescript/llms.txt) - **Java**: `com.x:xdk` (`v0.1.2`, Java 17+) — `implementation("com.x:xdk:0.1.2")` — [Index](https://docs.x.com/xdks/java/llms.txt) - **C#**: `XDevPlatform.Xdk` (`v0.1.2`, .NET 8.0+) — `dotnet add package XDevPlatform.Xdk` — [Index](https://docs.x.com/xdks/csharp/llms.txt) -## Overview & Guides +## Guides -- [XDKs Overview](https://docs.x.com/xdks/overview.md): Side-by-side comparison, authentication matrix, pagination, and streaming across all 4 official SDKs. +- [XDKs Overview](https://docs.x.com/xdks/overview.md): Packages, quickstart, and supported features across all four SDKs. - [Python Overview](https://docs.x.com/xdks/python/overview.md) | [Install](https://docs.x.com/xdks/python/install.md) | [Quickstart](https://docs.x.com/xdks/python/quickstart.md) | [Auth](https://docs.x.com/xdks/python/authentication.md) | [Pagination](https://docs.x.com/xdks/python/pagination.md) | [Streaming](https://docs.x.com/xdks/python/streaming.md) | [API Reference](https://docs.x.com/xdks/python/reference/overview.md) - [TypeScript Overview](https://docs.x.com/xdks/typescript/overview.md) | [Install](https://docs.x.com/xdks/typescript/install.md) | [Quickstart](https://docs.x.com/xdks/typescript/quickstart.md) | [Auth](https://docs.x.com/xdks/typescript/authentication.md) | [Pagination](https://docs.x.com/xdks/typescript/pagination.md) | [Streaming](https://docs.x.com/xdks/typescript/streaming.md) | [API Reference](https://docs.x.com/xdks/typescript/reference/overview.md) - [Java Overview](https://docs.x.com/xdks/java/overview.md) | [Install](https://docs.x.com/xdks/java/install.md) | [Quickstart](https://docs.x.com/xdks/java/quickstart.md) | [Auth](https://docs.x.com/xdks/java/authentication.md) | [Pagination](https://docs.x.com/xdks/java/pagination.md) | [Streaming](https://docs.x.com/xdks/java/streaming.md) | [API Reference](https://docs.x.com/xdks/java/reference/overview.md) - [C# Overview](https://docs.x.com/xdks/csharp/overview.md) | [Install](https://docs.x.com/xdks/csharp/install.md) | [Quickstart](https://docs.x.com/xdks/csharp/quickstart.md) | [Auth](https://docs.x.com/xdks/csharp/authentication.md) | [Pagination](https://docs.x.com/xdks/csharp/pagination.md) | [Streaming](https://docs.x.com/xdks/csharp/streaming.md) | [API Reference](https://docs.x.com/xdks/csharp/reference/overview.md) -## Resource Clients (Available in All 4 XDKs) +## Clients - **Account** (`AccountClient`, 2 operations): [Python](https://docs.x.com/xdks/python/reference/clients/account.md) | [TypeScript](https://docs.x.com/xdks/typescript/reference/clients/account.md) | [Java](https://docs.x.com/xdks/java/reference/clients/account.md) | [C#](https://docs.x.com/xdks/csharp/reference/clients/account.md) - **Account Activity** (`AccountActivityClient`, 5 operations): [Python](https://docs.x.com/xdks/python/reference/clients/account-activity.md) | [TypeScript](https://docs.x.com/xdks/typescript/reference/clients/account-activity.md) | [Java](https://docs.x.com/xdks/java/reference/clients/account-activity.md) | [C#](https://docs.x.com/xdks/csharp/reference/clients/account-activity.md) diff --git a/xdks/overview.mdx b/xdks/overview.mdx index 3cc4d2464..9f6dd1f58 100644 --- a/xdks/overview.mdx +++ b/xdks/overview.mdx @@ -1,43 +1,43 @@ --- -title: Official XDKs -sidebarTitle: XDKs Overview -description: Official, OpenAPI-generated client libraries for the X API v2 in Python, TypeScript, Java, and C# (.NET) with built-in OAuth, pagination, and streaming. +title: XDKs +sidebarTitle: All SDKs +description: Official client libraries for the X API v2 in Python, TypeScript, Java, and C#. keywords: ["XDK", "X SDK", "Python SDK", "TypeScript SDK", "Java SDK", "C# SDK", ".NET SDK", "X API v2", "client libraries"] --- -The **X Developer Kits (XDKs)** are the official client libraries for the X API v2. Every SDK is generated directly from the [official X API OpenAPI specification](https://api.x.com/2/openapi.json), keeping endpoint coverage, request/response models, authentication helpers, pagination, and streaming synchronized across languages. +The X Developer Kits (XDKs) are X's client libraries for the X API v2, generated from the [X API OpenAPI spec](https://api.x.com/2/openapi.json). - - `pip install xdk` — Python 3.8+, Pydantic v2 models, iterator pagination, and generator streaming. + + `pip install xdk` · Python 3.8+ - - `npm install @xdevplatform/xdk` — Node.js 18+, dual ESM/CommonJS, full TypeScript types, and `EventDrivenStream`. + + `npm install @xdevplatform/xdk` · Node.js 18+ - - `com.x:xdk:0.1.2` on Maven Central — Java 17+, builder-based `XClient`, `Paginator`, and `EventStream`. + + `com.x:xdk` · Java 17+ - - `dotnet add package XDevPlatform.Xdk` — .NET 8+, zero external runtime dependencies, `IAsyncEnumerable` paging & streaming. + + `dotnet add package XDevPlatform.Xdk` · .NET 8+ --- -## Compare Official SDKs +## Packages -| Language | Package | Runtime | Registry | Source Repository | +| Language | Package | Runtime | Registry | Repository | | :--- | :--- | :--- | :--- | :--- | -| **Python** | `xdk` | Python 3.8+ | [PyPI](https://pypi.org/project/xdk/) | [xdevplatform/xdk-python](https://github.com/xdevplatform/xdk-python) | -| **TypeScript / JS** | `@xdevplatform/xdk` | Node.js 18+ | [npm](https://www.npmjs.com/package/@xdevplatform/xdk) | [xdevplatform/xdk-typescript](https://github.com/xdevplatform/xdk-typescript) | -| **Java** | `com.x:xdk:0.1.2` | Java 17+ | [Maven Central](https://central.sonatype.com/artifact/com.x/xdk) | [xdevplatform/xdk-java](https://github.com/xdevplatform/xdk-java) | -| **C# / .NET** | `XDevPlatform.Xdk` | .NET 8.0+ | [NuGet](https://www.nuget.org/packages/XDevPlatform.Xdk) | [xdevplatform/xdk-csharp](https://github.com/xdevplatform/xdk-csharp) | +| **Python** | `xdk` | Python 3.8+ | [PyPI](https://pypi.org/project/xdk/) | [xdk-python](https://github.com/xdevplatform/xdk-python) | +| **TypeScript / JS** | `@xdevplatform/xdk` | Node.js 18+ | [npm](https://www.npmjs.com/package/@xdevplatform/xdk) | [xdk-typescript](https://github.com/xdevplatform/xdk-typescript) | +| **Java** | `com.x:xdk:0.1.2` | Java 17+ | [Maven Central](https://central.sonatype.com/artifact/com.x/xdk) | [xdk-java](https://github.com/xdevplatform/xdk-java) | +| **C# / .NET** | `XDevPlatform.Xdk` | .NET 8.0+ | [NuGet](https://www.nuget.org/packages/XDevPlatform.Xdk) | [xdk-csharp](https://github.com/xdevplatform/xdk-csharp) | --- -## Side-by-Side Quickstart +## Quickstart -Look up `@XDevelopers` using an app-only Bearer Token in any of the four official XDKs: +Look up `@XDevelopers` with a Bearer Token: @@ -127,21 +127,13 @@ Console.WriteLine(response.Data); --- -## Core Capabilities Across All 4 SDKs - -- **Unified Resource Clients**: Every X API v2 tag maps to a dedicated sub-client (`posts`, `users`, `stream`, `direct_messages` / `directMessages` / `DirectMessages`, `spaces`, `lists`, `communities`, `chat`, `media`, `webhooks`, `compliance`, `trends`, `news`, `usage`, and more). -- **Complete Authentication Support**: - - **Bearer Token** (app-only read, search, and filtered/sample streaming) - - **OAuth 2.0 User Context with PKCE** (fine-grained scopes + refresh token rotation) - - **OAuth 1.0a User Context** (HMAC-SHA1 request signing) -- **Native Pagination**: - - Python yields pages lazily via standard `Iterator` generators (`for page in client.posts.search_recent(...):`). - - TypeScript provides `Paginator`, `PostPaginator`, `UserPaginator`, and `EventPaginator` with `for await (...)`. - - Java exposes `*Pages(...)` methods returning `Paginator` (`Iterable`). - - C# exposes `*Pages(...)` methods returning `Paginator` (`IAsyncEnumerable`). -- **Resilient Real-Time Streaming**: - - Incremental UTF-8 NDJSON frame decoding, heartbeat handling, and resource cleanup across Filtered Stream, Sample Streams, Firehose, Compliance Streams, and Activity Stream. +## What's included + +- **Typed clients** — One sub-client per X API v2 resource (`posts`, `users`, `stream`, `direct_messages`, `spaces`, `lists`, `media`, `webhooks`, `chat`, and more). +- **Authentication** — Bearer Token, OAuth 2.0 with PKCE and token refresh, and OAuth 1.0a. +- **Pagination** — Cursor handling via Python generators, TypeScript `Paginator`, Java `Paginator`, and C# `IAsyncEnumerable`. +- **Streaming** — Live event streams for Filtered Stream, Sample Streams, Firehose, Compliance, and Activity. -Building encrypted direct messaging with the X Chat API? Pair any of these XDKs with the [Chat XDK](/xchat/xchat-xdk) (available in Python, TypeScript, Java, C#, Go, and Rust) for client-side key management, encryption, and message signing. +For encrypted X Chat messages, see the [Chat XDK](/xchat/xchat-xdk) (Python, TypeScript, Java, C#, Go, and Rust). diff --git a/xdks/python/authentication.mdx b/xdks/python/authentication.mdx index 7df9c7f4e..f5301ad68 100644 --- a/xdks/python/authentication.mdx +++ b/xdks/python/authentication.mdx @@ -1,137 +1,111 @@ --- title: Authentication sidebarTitle: Authentication -description: "Authenticate the Python XDK with Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a user context to call X API endpoints and post on behalf of users." +description: Configure Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a in the Python XDK. --- -The X API requires authentication for all endpoints. The XDK supports three authentication methods: -1. Bearer Token (app-only) -2. OAuth 2.0 with PKCE -3. OAuth 1.0a (User Context) -- **Bearer Token**: Use this for read-only access for endpoints that support app-auth (e.g., searching Post's, streaming endpoints). -- **OAuth 2.0 PKCE**: Secure authentication for scope-based, user-authorized access (e.g. getting authenticated user's Post non_public metrics) -- **OAuth 1.0a**: Legacy authentication for user-specific operations (e.g., posting on behalf of a user, managing lists) -Obtain credentials from the [X Developer Console](https://developer.x.com/en/portal/dashboard). You'll need an approved developer account and an app with appropriate permissions (e.g., Read + Write). -## Creating a Client -All authentication flows create a `Client` instance: + +`Client` supports three X API v2 auth modes: + +- **Bearer Token (app-only)**: Public read, search, and streaming endpoints. +- **OAuth 2.0 PKCE (user context)**: Scoped user actions (creating posts, bookmarks, DMs, X Chat) with refresh tokens. +- **OAuth 1.0a (user context)**: HMAC-SHA1 request signing. + +Get your app credentials from the [X Developer Console](https://console.x.com). + +## Bearer Token + ```python +import os from xdk import Client -``` -### 1. Bearer Token (App-Only) -For read-only operations without user context. -**Steps**: -1. In the Developer Console, generate a Bearer Token for your app. -2. Pass it to the `Client`. -**Example**: -```python -client = Client(bearer_token="XXXXX") -``` -**Usage**: -```python -# search_recent returns an Iterator, so iterate over it + +client = Client(bearer_token=os.environ["X_BEARER_TOKEN"]) + for page in client.posts.search_recent(query="python", max_results=10): - if page.data and len(page.data) > 0: - first_post = page.data[0] - post_text = first_post.text if hasattr(first_post, 'text') else first_post.get('text', '') - print(post_text) # Access first Post - break + if page.data: + print(page.data[0].text) + break ``` -### 2. OAuth 2.0 with PKCE (User Context) -This example shows how to use OAuth 2.0 with Proof Key for Code Exchange (PKCE). Use this for user-specific access (e.g. posting on behalf of a user), uploading media for a user etc.). -**Steps**: -1. In the Developer Console, register your app with a redirect URI (e.g., `http://localhost:8080/callback`). -2. Get Client ID (no secret needed for PKCE). -3. Initiate the flow, direct user to auth URL and handle callback. -**Example** (using a web server for callback): -```python title="Example" expandable lines wrap icon="python" -from xdk.oauth2_auth import OAuth2PKCEAuth -from urllib.parse import urlparse + +## OAuth 2.0 with PKCE + +Register a redirect URI (for example, `http://localhost:8080/callback`) on your app in the Developer Console, then run the PKCE flow with `OAuth2PKCEAuth`: + +```python +import os import webbrowser -# Step 1: Create PKCE instance +from xdk import Client +from xdk.oauth2_auth import OAuth2PKCEAuth + auth = OAuth2PKCEAuth( - client_id="YOUR_CLIENT_ID", - redirect_uri="YOUR_CALLBACK_URL", - scope="tweet.read users.read offline.access" + client_id=os.environ["X_CLIENT_ID"], + redirect_uri="http://localhost:8080/callback", + scope="tweet.read users.read offline.access", ) -# Step 2: Get authorization URL + auth_url = auth.get_authorization_url() -print(f"Visit this URL to authorize: {auth_url}") +print(f"Authorize here: {auth_url}") webbrowser.open(auth_url) -# Step 3: Handle callback (in a real app, use a web framework like Flask) -# Assume callback_url = "http://localhost:8080/callback?code=AUTH_CODE_HERE" -callback_url = input("Paste the full callback URL here: ") -# Step 4: Exchange code for tokens + +callback_url = input("Paste the full callback URL: ") tokens = auth.fetch_token(authorization_response=callback_url) -access_token = tokens["access_token"] -refresh_token = tokens["refresh_token"] # Store for renewal -# Step 5: Create client -# Option 1: Use bearer_token (OAuth2 access tokens work as bearer tokens) -client = Client(bearer_token=access_token) -# Option 2: Pass the full token dict for automatic refresh support -# client = Client(token=tokens) + +# Pass the access token directly, or pass `token=tokens` for refresh support +client = Client(access_token=tokens["access_token"]) ``` -**Token Refresh** (automatic in SDK for long-lived sessions): + +### Refreshing tokens + ```python -# If access token expires, refresh using stored refresh_token -# The refresh_token method uses the stored token from the OAuth2PKCEAuth instance tokens = auth.refresh_token() -# Use the refreshed token -client = Client(bearer_token=tokens["access_token"]) -# Or pass the full token dict: client = Client(token=tokens) +client = Client(access_token=tokens["access_token"]) ``` -### 3. OAuth 1.0a (User Context) -For legacy applications or specific use cases that require OAuth 1.0a authentication: -**Steps**: -1. In the Developer Console, get your API Key and API Secret. -2. If you already have access tokens, use them directly. Otherwise, complete the OAuth 1.0a flow to obtain them. -3. Create an OAuth1 instance and pass it to the Client. -**Example** (with existing access tokens): -```python title="Example" lines wrap icon="python" + +## OAuth 1.0a + +With existing access tokens: + +```python +import os from xdk import Client from xdk.oauth1_auth import OAuth1 -# Step 1: Create OAuth1 instance with credentials + oauth1 = OAuth1( - api_key="YOUR_API_KEY", - api_secret="YOUR_API_SECRET", + api_key=os.environ["X_API_KEY"], + api_secret=os.environ["X_API_SECRET"], callback="http://localhost:8080/callback", - access_token="YOUR_ACCESS_TOKEN", - access_token_secret="YOUR_ACCESS_TOKEN_SECRET" + access_token=os.environ["X_ACCESS_TOKEN"], + access_token_secret=os.environ["X_ACCESS_TOKEN_SECRET"], ) -# Step 2: Create client with OAuth1 + client = Client(auth=oauth1) -# Step 3: Use the client response = client.users.get_me() -me = response.data -print(me) +print(response.data) ``` -**Example** (complete OAuth 1.0a flow): -```python title="Example" lines wrap icon="python" + +Or run the full 3-legged flow: + +```python +import os +import webbrowser from xdk import Client from xdk.oauth1_auth import OAuth1 -import webbrowser -# Step 1: Create OAuth1 instance + oauth1 = OAuth1( - api_key="YOUR_API_KEY", - api_secret="YOUR_API_SECRET", - callback="http://localhost:8080/callback" + api_key=os.environ["X_API_KEY"], + api_secret=os.environ["X_API_SECRET"], + callback="http://localhost:8080/callback", ) -# Step 2: Get request token -request_token = oauth1.get_request_token() -# Step 3: Get authorization URL + +oauth1.get_request_token() auth_url = oauth1.get_authorization_url(login_with_x=False) -print(f"Visit this URL to authorize: {auth_url}") +print(f"Authorize here: {auth_url}") webbrowser.open(auth_url) -# Step 4: User authorizes and you receive oauth_verifier -# In a real app, handle this via callback URL -oauth_verifier = input("Enter the OAuth verifier from the callback: ") -# Step 5: Exchange for access token -access_token = oauth1.get_access_token(oauth_verifier) -# Step 6: Create client + +verifier = input("Enter oauth_verifier: ") +oauth1.get_access_token(verifier) + client = Client(auth=oauth1) -# Now you can use the client -response = client.users.get_me() +print(client.users.get_me().data) ``` -**Note**: -- Never hardcode secrets in production; use environment variables or secret managers (e.g., `os.getenv("X_BEARER_TOKEN")`). -- For PKCE, ensure HTTPS for redirect URIs in production. -- The SDK validates tokens and raises `xdk.AuthenticationError` on failures. -For detailed code examples using the Python XDK, check out our [code samples GitHub repo](https://github.com/xdevplatform/samples/tree/main/python). + +See the [Python samples repo](https://github.com/xdevplatform/samples/tree/main/python) for more examples. diff --git a/xdks/python/install.mdx b/xdks/python/install.mdx index 32471713f..f9dd4d3e8 100644 --- a/xdks/python/install.mdx +++ b/xdks/python/install.mdx @@ -1,17 +1,10 @@ --- -title: Install Python XDK +title: Install sidebarTitle: Install -description: Install the official Python XDK (xdk) from PyPI with pip or uv, set up a virtual environment, or install from source for Python 3.8+. +description: Install the Python XDK from PyPI or from source. --- -Install the official **Python XDK** (`xdk`) from [PyPI](https://pypi.org/project/xdk/). - -## Prerequisites - -- **Python 3.8+** (CPython or PyPy) -- `pip` or `uv` - -## Install from PyPI +Install `xdk` from [PyPI](https://pypi.org/project/xdk/). Requires Python 3.8+. @@ -29,7 +22,7 @@ poetry add xdk -## Virtual Environment Setup (Recommended) +## Virtual environment ```bash python3 -m venv .venv @@ -37,16 +30,15 @@ source .venv/bin/activate pip install xdk ``` -## Verify Installation +## Verify ```python import xdk -from xdk import Client print(xdk.__version__) ``` -## Install from Source +## Install from source ```bash git clone https://github.com/xdevplatform/xdk-python.git @@ -54,8 +46,8 @@ cd xdk-python pip install -e ".[dev]" ``` -## Next Steps +## Next steps -- [Quickstart](/xdks/python/quickstart) — Run your first search query -- [Authentication](/xdks/python/authentication) — Configure Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a -- [API Reference](/xdks/python/reference/overview) — Browse all 24 resource clients +- [Quickstart](/xdks/python/quickstart) +- [Authentication](/xdks/python/authentication) +- [API Reference](/xdks/python/reference/overview) diff --git a/xdks/python/llms.txt b/xdks/python/llms.txt index e290f6357..1ea70a8bd 100644 --- a/xdks/python/llms.txt +++ b/xdks/python/llms.txt @@ -1,19 +1,19 @@ # Python XDK (`xdk` v0.11.2) -> Official Python SDK for the X API v2 (Python 3.8+). Install with `pip install xdk`. +> Official Python client library for the X API v2 (Python 3.8+). Install with `pip install xdk`. ## Guides -- [Python overview](https://docs.x.com/xdks/python/overview.md): Architecture, capabilities, and client overview -- [Python install](https://docs.x.com/xdks/python/install.md): Package installation and runtime requirements -- [Python quickstart](https://docs.x.com/xdks/python/quickstart.md): First authenticated X API v2 request in under 2 minutes -- [Python authentication](https://docs.x.com/xdks/python/authentication.md): Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a user-context setup -- [Python pagination](https://docs.x.com/xdks/python/pagination.md): Automatic cursor iteration across multi-page endpoints -- [Python streaming](https://docs.x.com/xdks/python/streaming.md): Real-time event streams with reconnection and lifecycle handling +- [Python overview](https://docs.x.com/xdks/python/overview.md): Overview and quick example +- [Python install](https://docs.x.com/xdks/python/install.md): Installation and requirements +- [Python quickstart](https://docs.x.com/xdks/python/quickstart.md): Make your first X API v2 request +- [Python authentication](https://docs.x.com/xdks/python/authentication.md): Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a +- [Python pagination](https://docs.x.com/xdks/python/pagination.md): Cursor pagination across multi-page endpoints +- [Python streaming](https://docs.x.com/xdks/python/streaming.md): Real-time event streams and filtered stream rules ## Client Reference -- [Reference Overview](https://docs.x.com/xdks/python/reference/overview.md): Main client options and resource client directory +- [Reference Overview](https://docs.x.com/xdks/python/reference/overview.md): Client options and client list - [`AccountClient` (Account)](https://docs.x.com/xdks/python/reference/clients/account.md): 2 methods via `client.account` - [`AccountActivityClient` (Account Activity)](https://docs.x.com/xdks/python/reference/clients/account-activity.md): 5 methods via `client.account_activity` - [`ActivityClient` (Activity)](https://docs.x.com/xdks/python/reference/clients/activity.md): 5 methods via `client.activity` diff --git a/xdks/python/overview.mdx b/xdks/python/overview.mdx index ea596ed1f..5768845b3 100644 --- a/xdks/python/overview.mdx +++ b/xdks/python/overview.mdx @@ -1,29 +1,21 @@ --- title: Python XDK sidebarTitle: Overview -description: Official Python SDK (xdk) for the X API v2 with Pydantic v2 models, OAuth 2.0 PKCE, OAuth 1.0a, automatic cursor pagination, and real-time streaming. +description: Python client library for the X API v2. --- -The **Python XDK** (`xdk`) is X's official Python client library for the X API v2, generated directly from the [official OpenAPI specification](https://api.x.com/2/openapi.json). +`xdk` is the official Python SDK for the X API v2. It includes typed Pydantic models, OAuth 2.0 PKCE and OAuth 1.0a auth, cursor pagination, and streaming. - - `pip install xdk` — Python 3.8+. + + `pip install xdk` · Python 3.8+ - - Source code, release notes, and issue tracker. + + Source code and issues. -## Key Features - -- **Authentication**: App-only Bearer Token, OAuth 2.0 User Context with PKCE and token refresh, and OAuth 1.0a HMAC-SHA1 signing. -- **Typed Models**: Pydantic v2 request and response models with open-enum forward compatibility. -- **Automatic Pagination**: Generator-based cursor iteration across multi-page endpoints without manual `pagination_token` loops. -- **Real-Time Streaming**: Persistent streaming iterators for Filtered Stream, Sample Streams, Firehose, Compliance, and Activity Stream. -- **Complete API Coverage**: 24 resource clients covering Posts, Users, Streams, Direct Messages, Chat, Spaces, Lists, Communities, Media, Webhooks, Trends, News, Usage, and more. - -## Quick Example +## Quick example ```python import os @@ -38,25 +30,25 @@ for page in client.posts.search_recent(query="from:XDevelopers", max_results=10) break ``` -## Guides & Reference +## Guides - Install from PyPI or set up a virtual environment. + Install with pip, uv, or poetry. - Make your first X API v2 call in Python. + Run your first search query. - Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a setup. + Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a. - Iterate across multi-page endpoints lazily. + Iterate across multi-page endpoints. - Consume real-time post and activity streams. + Filtered streams and rule management. - - Full method & parameter reference for all 24 clients. + + Methods and parameters for each client. diff --git a/xdks/python/pagination.mdx b/xdks/python/pagination.mdx index b949efc84..9cd5fd3e4 100644 --- a/xdks/python/pagination.mdx +++ b/xdks/python/pagination.mdx @@ -1,60 +1,52 @@ --- title: Pagination sidebarTitle: Pagination -description: "Page through X API results in Python using the XDK iterator for automatic next_token handling, or manage pagination_token manually for custom paging logic." +description: Paginate X API v2 responses in Python with iterators or manual pagination tokens. --- -The X API uses pagination for endpoints that return multiple pages of results (e.g. timelines, search etc.). Each API call response includes a `meta` object with `result_count`, `previous_token`, and `next_token`. The XDK takes care of making multiple API calls using the `next_token` so developers can just specify how much data they are looking for without having to make multiple calls. -The SDK simplifies this with: -- **Built-in Iterators**: Use generator functions for seamless multi-page fetching. -- **Explicit Token Handling**: For flexible manual control when needed by passing `pagination_token` when needed. -- **Max Results Enforcement**: Respect `max_results` per call (up to API limits, e.g., 100 for search). -## Automatic Pagination (Recommended) -Use the `iterate()` method on paginated responses to fetch all results lazily. -**Example: Paginated Search** -```python title="Example" lines wrap icon="python" + +Paginated methods in the Python XDK return a lazy iterator that follows `meta.next_token` automatically across pages. + +## Automatic pagination + +```python +import os from xdk import Client -client = Client(bearer_token="your_bearer_token") -# Search with automatic pagination + +client = Client(bearer_token=os.environ["X_BEARER_TOKEN"]) + all_posts = [] for page in client.posts.search_recent( query="python", - max_results=100, # Per page - tweet_fields=["created_at", "author_id"] # Optional expansions + max_results=100, + tweet_fields=["created_at", "author_id"], ): - all_posts.extend(page.data) - print(f"Fetched {len(page.data)} Posts (total: {len(all_posts)})") -print(f"Total tweets: {len(all_posts)}") + if page.data: + all_posts.extend(page.data) + print(f"Fetched {len(page.data)} posts (total: {len(all_posts)})") + if len(all_posts) >= 500: + break # Stop early without fetching additional pages ``` -- The iterator handles `next_token` automatically. -- Stops when no `next_token` is present. -- Supports rate limit backoff to avoid 429 errors. -## Manual Pagination -If you require control over the results for some custom logic (e.g. processing page-by-page), you can still use the `next_token` and do the pagination manually as shown below: -```python title="Example" lines wrap icon="python" -# Get first page - search_recent returns an Iterator + +The iterator stops automatically when `meta.next_token` is absent. + +## Manual pagination + +To control each request yourself, pull a single page with `next(...)` and pass `pagination_token` on the next call: + +```python first_page = next(client.posts.search_recent( - query="xdk python sdk", + query="python", max_results=100, - pagination_token=None # First page )) -print(f"First page: {len(first_page.data) if first_page.data else 0} Posts") -# Extract next_token from meta -next_token = None -if hasattr(first_page, 'meta') and first_page.meta: - if hasattr(first_page.meta, 'next_token'): - next_token = first_page.meta.next_token - elif isinstance(first_page.meta, dict): - next_token = first_page.meta.get('next_token') + +next_token = first_page.meta.next_token if first_page.meta else None if next_token: second_page = next(client.posts.search_recent( - query="xdk python sdk", + query="python", max_results=100, - pagination_token=next_token + pagination_token=next_token, )) - print(f"Second page: {len(second_page.data) if second_page.data else 0} Posts") + print(f"Second page: {len(second_page.data or [])} posts") ``` -**Tips**: -- Always specify `max_results` to optimize (default varies by endpoint). -- Monitor `meta.result_count` for debugging. -- For very large queries, consider async iteration to avoid blocking. -For detailed code examples using the Python XDK, check out our [code samples GitHub repo](https://github.com/xdevplatform/samples/tree/main/python). + +See the [Python samples repo](https://github.com/xdevplatform/samples/tree/main/python) for more examples. diff --git a/xdks/python/quickstart.mdx b/xdks/python/quickstart.mdx index 27d8b9c72..208b2bc64 100644 --- a/xdks/python/quickstart.mdx +++ b/xdks/python/quickstart.mdx @@ -1,49 +1,50 @@ --- title: Quickstart sidebarTitle: Quickstart - -description: "This example showcases how to quickly search for Posts using the XDK using Bearer Token authentication. 1. Log in to the X Developer Console. 2." +description: Make your first X API v2 request with the Python XDK. --- -This example showcases how to quickly search for Posts using the XDK using Bearer Token authentication. -## Step 1: Install the SDK + + + ```bash pip install xdk ``` -## Step 2: Get Your Bearer Token -1. Log in to the [X Developer Console](https://developer.x.com/en/portal/dashboard). -2. Create or select an app. -3. Under "Keys and Tokens," generate a Bearer Token (app-only auth). -## Step 3: Write and Run Your First Script -Create a file `quickstart.py`: -```python title="Example" lines wrap icon="python" -# Import the client + + + Generate a **Bearer Token** in the [X Developer Console](https://console.x.com) and set it in your shell: + +```bash +export X_BEARER_TOKEN="your_bearer_token_here" +``` + + + Save this as `quickstart.py`: + +```python +import os from xdk import Client -# Replace with your actual Bearer Token -client = Client(bearer_token="YOUR_BEARER_TOKEN_HERE") -# Fetch recent Posts mentioning "api" -# search_recent returns an Iterator, so iterate over it -for page in client.posts.search_recent(query="api", max_results=10): - if page.data and len(page.data) > 0: - # Access first Post - Pydantic models support both attribute and dict access - first_post = page.data[0] - post_text = first_post.text if hasattr(first_post, 'text') else first_post.get('text', '') - print(f"Latest Post: {post_text}") - break + +client = Client(bearer_token=os.environ["X_BEARER_TOKEN"]) + +for page in client.posts.search_recent(query="from:XDevelopers", max_results=10): + if page.data: + print(page.data[0].text) else: - print("No Posts found.") - break + print("No posts found.") + break ``` -Run it: + + Run it: + ```bash python quickstart.py ``` -**Expected Output**: -``` -Latest Post: Exciting updates on XDK Python SDK! -``` -**Troubleshooting**: If you get a 401 error, double-check your Bearer Token. For rate limits (429), wait and retry. -## Next Steps -- Explore [Authentication](/xdks/python/authentication) to understand how to use Bearer Token (app-only) auth, OAuth 2.0 with PKCE (user context), and OAuth 1.0a (legacy user context). -- Learn about [Pagination](/xdks/python/pagination) for use-cases where you want large number of results returned without worrying about making multiple API calls. -- Dive into [Streaming](/xdks/python/streaming) to learn how to work with real-time data. -For detailed code examples using the Python XDK, check out our [code samples GitHub repo](https://github.com/xdevplatform/samples/tree/main/python). + + + +## Next steps + +- [Authentication](/xdks/python/authentication) — Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a +- [Pagination](/xdks/python/pagination) — Fetch multiple pages with iterators +- [Streaming](/xdks/python/streaming) — Read real-time filtered and sampled streams +- [Code samples](https://github.com/xdevplatform/samples/tree/main/python) — Runnable Python examples diff --git a/xdks/python/reference/clients/account-activity.mdx b/xdks/python/reference/clients/account-activity.mdx index ceeaee01e..0e0b6c3a1 100644 --- a/xdks/python/reference/clients/account-activity.mdx +++ b/xdks/python/reference/clients/account-activity.mdx @@ -1,7 +1,7 @@ --- -title: "AccountActivityClient (Python XDK)" +title: "AccountActivityClient" sidebarTitle: "Account Activity" -description: "Python XDK AccountActivityClient reference — 5 methods for X API v2 Account Activity endpoints." +description: "Methods for X API v2 Account Activity endpoints." --- Access **Account Activity** endpoints via `client.account_activity` (`AccountActivityClient`). diff --git a/xdks/python/reference/clients/account.mdx b/xdks/python/reference/clients/account.mdx index 62fb6fb86..918095952 100644 --- a/xdks/python/reference/clients/account.mdx +++ b/xdks/python/reference/clients/account.mdx @@ -1,7 +1,7 @@ --- -title: "AccountClient (Python XDK)" +title: "AccountClient" sidebarTitle: "Account" -description: "Python XDK AccountClient reference — 2 methods for X API v2 Account endpoints." +description: "Methods for X API v2 Account endpoints." --- Access **Account** endpoints via `client.account` (`AccountClient`). diff --git a/xdks/python/reference/clients/activity.mdx b/xdks/python/reference/clients/activity.mdx index 2d293d358..cff90b915 100644 --- a/xdks/python/reference/clients/activity.mdx +++ b/xdks/python/reference/clients/activity.mdx @@ -1,7 +1,7 @@ --- -title: "ActivityClient (Python XDK)" +title: "ActivityClient" sidebarTitle: "Activity" -description: "Python XDK ActivityClient reference — 5 methods for X API v2 Activity endpoints." +description: "Methods for X API v2 Activity endpoints." --- Access **Activity** endpoints via `client.activity` (`ActivityClient`). diff --git a/xdks/python/reference/clients/articles.mdx b/xdks/python/reference/clients/articles.mdx index 5d7ee452a..012195814 100644 --- a/xdks/python/reference/clients/articles.mdx +++ b/xdks/python/reference/clients/articles.mdx @@ -1,7 +1,7 @@ --- -title: "ArticlesClient (Python XDK)" +title: "ArticlesClient" sidebarTitle: "Articles" -description: "Python XDK ArticlesClient reference — 2 methods for X API v2 Articles endpoints." +description: "Methods for X API v2 Articles endpoints." --- Access **Articles** endpoints via `client.articles` (`ArticlesClient`). diff --git a/xdks/python/reference/clients/bots.mdx b/xdks/python/reference/clients/bots.mdx index 2ced0bfe4..94e362f4f 100644 --- a/xdks/python/reference/clients/bots.mdx +++ b/xdks/python/reference/clients/bots.mdx @@ -1,7 +1,7 @@ --- -title: "BotsClient (Python XDK)" +title: "BotsClient" sidebarTitle: "Bots" -description: "Python XDK BotsClient reference — 6 methods for X API v2 Bots endpoints." +description: "Methods for X API v2 Bots endpoints." --- Access **Bots** endpoints via `client.bots` (`BotsClient`). diff --git a/xdks/python/reference/clients/broadcasts.mdx b/xdks/python/reference/clients/broadcasts.mdx index f61f1e9da..3c6ac31f2 100644 --- a/xdks/python/reference/clients/broadcasts.mdx +++ b/xdks/python/reference/clients/broadcasts.mdx @@ -1,7 +1,7 @@ --- -title: "BroadcastsClient (Python XDK)" +title: "BroadcastsClient" sidebarTitle: "Broadcasts" -description: "Python XDK BroadcastsClient reference — 41 methods for X API v2 Broadcasts endpoints." +description: "Methods for X API v2 Broadcasts endpoints." --- Access **Broadcasts** endpoints via `client.broadcasts` (`BroadcastsClient`). diff --git a/xdks/python/reference/clients/calls.mdx b/xdks/python/reference/clients/calls.mdx index 41e3b545d..b763eedc8 100644 --- a/xdks/python/reference/clients/calls.mdx +++ b/xdks/python/reference/clients/calls.mdx @@ -1,7 +1,7 @@ --- -title: "CallsClient (Python XDK)" +title: "CallsClient" sidebarTitle: "Calls" -description: "Python XDK CallsClient reference — 10 methods for X API v2 Calls endpoints." +description: "Methods for X API v2 Calls endpoints." --- Access **Calls** endpoints via `client.calls` (`CallsClient`). diff --git a/xdks/python/reference/clients/chat.mdx b/xdks/python/reference/clients/chat.mdx index 569536e29..4f0922646 100644 --- a/xdks/python/reference/clients/chat.mdx +++ b/xdks/python/reference/clients/chat.mdx @@ -1,7 +1,7 @@ --- -title: "ChatClient (Python XDK)" +title: "ChatClient" sidebarTitle: "Chat" -description: "Python XDK ChatClient reference — 45 methods for X API v2 Chat endpoints." +description: "Methods for X API v2 Chat endpoints." --- Access **Chat** endpoints via `client.chat` (`ChatClient`). diff --git a/xdks/python/reference/clients/communities.mdx b/xdks/python/reference/clients/communities.mdx index 1333b9d61..e80737863 100644 --- a/xdks/python/reference/clients/communities.mdx +++ b/xdks/python/reference/clients/communities.mdx @@ -1,7 +1,7 @@ --- -title: "CommunitiesClient (Python XDK)" +title: "CommunitiesClient" sidebarTitle: "Communities" -description: "Python XDK CommunitiesClient reference — 2 methods for X API v2 Communities endpoints." +description: "Methods for X API v2 Communities endpoints." --- Access **Communities** endpoints via `client.communities` (`CommunitiesClient`). diff --git a/xdks/python/reference/clients/community-notes.mdx b/xdks/python/reference/clients/community-notes.mdx index efd3ca429..080bb7aa0 100644 --- a/xdks/python/reference/clients/community-notes.mdx +++ b/xdks/python/reference/clients/community-notes.mdx @@ -1,7 +1,7 @@ --- -title: "CommunityNotesClient (Python XDK)" +title: "CommunityNotesClient" sidebarTitle: "Community Notes" -description: "Python XDK CommunityNotesClient reference — 5 methods for X API v2 Community Notes endpoints." +description: "Methods for X API v2 Community Notes endpoints." --- Access **Community Notes** endpoints via `client.community_notes` (`CommunityNotesClient`). diff --git a/xdks/python/reference/clients/compliance.mdx b/xdks/python/reference/clients/compliance.mdx index 3acfdd7bc..1a8a2958c 100644 --- a/xdks/python/reference/clients/compliance.mdx +++ b/xdks/python/reference/clients/compliance.mdx @@ -1,7 +1,7 @@ --- -title: "ComplianceClient (Python XDK)" +title: "ComplianceClient" sidebarTitle: "Compliance" -description: "Python XDK ComplianceClient reference — 6 methods for X API v2 Compliance endpoints." +description: "Methods for X API v2 Compliance endpoints." --- Access **Compliance** endpoints via `client.compliance` (`ComplianceClient`). diff --git a/xdks/python/reference/clients/connections.mdx b/xdks/python/reference/clients/connections.mdx index af0824533..9a14662b8 100644 --- a/xdks/python/reference/clients/connections.mdx +++ b/xdks/python/reference/clients/connections.mdx @@ -1,7 +1,7 @@ --- -title: "ConnectionsClient (Python XDK)" +title: "ConnectionsClient" sidebarTitle: "Connections" -description: "Python XDK ConnectionsClient reference — 4 methods for X API v2 Connections endpoints." +description: "Methods for X API v2 Connections endpoints." --- Access **Connections** endpoints via `client.connections` (`ConnectionsClient`). diff --git a/xdks/python/reference/clients/direct-messages.mdx b/xdks/python/reference/clients/direct-messages.mdx index c51f67d02..7be58041d 100644 --- a/xdks/python/reference/clients/direct-messages.mdx +++ b/xdks/python/reference/clients/direct-messages.mdx @@ -1,7 +1,7 @@ --- -title: "DirectMessagesClient (Python XDK)" +title: "DirectMessagesClient" sidebarTitle: "Direct Messages" -description: "Python XDK DirectMessagesClient reference — 9 methods for X API v2 Direct Messages endpoints." +description: "Methods for X API v2 Direct Messages endpoints." --- Access **Direct Messages** endpoints via `client.direct_messages` (`DirectMessagesClient`). diff --git a/xdks/python/reference/clients/general.mdx b/xdks/python/reference/clients/general.mdx index c704d1681..08f3d51b7 100644 --- a/xdks/python/reference/clients/general.mdx +++ b/xdks/python/reference/clients/general.mdx @@ -1,7 +1,7 @@ --- -title: "GeneralClient (Python XDK)" +title: "GeneralClient" sidebarTitle: "General" -description: "Python XDK GeneralClient reference — 1 methods for X API v2 General endpoints." +description: "Methods for X API v2 General endpoints." --- Access **General** endpoints via `client.general` (`GeneralClient`). diff --git a/xdks/python/reference/clients/lists.mdx b/xdks/python/reference/clients/lists.mdx index 69e184b4a..fe8090995 100644 --- a/xdks/python/reference/clients/lists.mdx +++ b/xdks/python/reference/clients/lists.mdx @@ -1,7 +1,7 @@ --- -title: "ListsClient (Python XDK)" +title: "ListsClient" sidebarTitle: "Lists" -description: "Python XDK ListsClient reference — 9 methods for X API v2 Lists endpoints." +description: "Methods for X API v2 Lists endpoints." --- Access **Lists** endpoints via `client.lists` (`ListsClient`). diff --git a/xdks/python/reference/clients/media.mdx b/xdks/python/reference/clients/media.mdx index 8478a84c6..caef4fa87 100644 --- a/xdks/python/reference/clients/media.mdx +++ b/xdks/python/reference/clients/media.mdx @@ -1,7 +1,7 @@ --- -title: "MediaClient (Python XDK)" +title: "MediaClient" sidebarTitle: "Media" -description: "Python XDK MediaClient reference — 19 methods for X API v2 Media endpoints." +description: "Methods for X API v2 Media endpoints." --- Access **Media** endpoints via `client.media` (`MediaClient`). diff --git a/xdks/python/reference/clients/news.mdx b/xdks/python/reference/clients/news.mdx index 64443a429..0695aa865 100644 --- a/xdks/python/reference/clients/news.mdx +++ b/xdks/python/reference/clients/news.mdx @@ -1,7 +1,7 @@ --- -title: "NewsClient (Python XDK)" +title: "NewsClient" sidebarTitle: "News" -description: "Python XDK NewsClient reference — 2 methods for X API v2 News endpoints." +description: "Methods for X API v2 News endpoints." --- Access **News** endpoints via `client.news` (`NewsClient`). diff --git a/xdks/python/reference/clients/posts.mdx b/xdks/python/reference/clients/posts.mdx index 6fc31ee6e..fec0e7887 100644 --- a/xdks/python/reference/clients/posts.mdx +++ b/xdks/python/reference/clients/posts.mdx @@ -1,7 +1,7 @@ --- -title: "PostsClient (Python XDK)" +title: "PostsClient" sidebarTitle: "Posts" -description: "Python XDK PostsClient reference — 17 methods for X API v2 Posts endpoints." +description: "Methods for X API v2 Posts endpoints." --- Access **Posts** endpoints via `client.posts` (`PostsClient`). diff --git a/xdks/python/reference/clients/spaces.mdx b/xdks/python/reference/clients/spaces.mdx index fe92a0039..a4d739733 100644 --- a/xdks/python/reference/clients/spaces.mdx +++ b/xdks/python/reference/clients/spaces.mdx @@ -1,7 +1,7 @@ --- -title: "SpacesClient (Python XDK)" +title: "SpacesClient" sidebarTitle: "Spaces" -description: "Python XDK SpacesClient reference — 6 methods for X API v2 Spaces endpoints." +description: "Methods for X API v2 Spaces endpoints." --- Access **Spaces** endpoints via `client.spaces` (`SpacesClient`). diff --git a/xdks/python/reference/clients/stream.mdx b/xdks/python/reference/clients/stream.mdx index 5e51484bf..f347b5a67 100644 --- a/xdks/python/reference/clients/stream.mdx +++ b/xdks/python/reference/clients/stream.mdx @@ -1,7 +1,7 @@ --- -title: "StreamClient (Python XDK)" +title: "StreamClient" sidebarTitle: "Stream" -description: "Python XDK StreamClient reference — 18 methods for X API v2 Stream endpoints." +description: "Methods for X API v2 Stream endpoints." --- Access **Stream** endpoints via `client.stream` (`StreamClient`). diff --git a/xdks/python/reference/clients/trends.mdx b/xdks/python/reference/clients/trends.mdx index d920a6062..b05515e0e 100644 --- a/xdks/python/reference/clients/trends.mdx +++ b/xdks/python/reference/clients/trends.mdx @@ -1,7 +1,7 @@ --- -title: "TrendsClient (Python XDK)" +title: "TrendsClient" sidebarTitle: "Trends" -description: "Python XDK TrendsClient reference — 3 methods for X API v2 Trends endpoints." +description: "Methods for X API v2 Trends endpoints." --- Access **Trends** endpoints via `client.trends` (`TrendsClient`). diff --git a/xdks/python/reference/clients/usage.mdx b/xdks/python/reference/clients/usage.mdx index 734379e79..f7dbe4c61 100644 --- a/xdks/python/reference/clients/usage.mdx +++ b/xdks/python/reference/clients/usage.mdx @@ -1,7 +1,7 @@ --- -title: "UsageClient (Python XDK)" +title: "UsageClient" sidebarTitle: "Usage" -description: "Python XDK UsageClient reference — 2 methods for X API v2 Usage endpoints." +description: "Methods for X API v2 Usage endpoints." --- Access **Usage** endpoints via `client.usage` (`UsageClient`). diff --git a/xdks/python/reference/clients/users.mdx b/xdks/python/reference/clients/users.mdx index a2eb7219e..252bc0985 100644 --- a/xdks/python/reference/clients/users.mdx +++ b/xdks/python/reference/clients/users.mdx @@ -1,7 +1,7 @@ --- -title: "UsersClient (Python XDK)" +title: "UsersClient" sidebarTitle: "Users" -description: "Python XDK UsersClient reference — 46 methods for X API v2 Users endpoints." +description: "Methods for X API v2 Users endpoints." --- Access **Users** endpoints via `client.users` (`UsersClient`). diff --git a/xdks/python/reference/clients/webhooks.mdx b/xdks/python/reference/clients/webhooks.mdx index 0416fa190..d80f08582 100644 --- a/xdks/python/reference/clients/webhooks.mdx +++ b/xdks/python/reference/clients/webhooks.mdx @@ -1,7 +1,7 @@ --- -title: "WebhooksClient (Python XDK)" +title: "WebhooksClient" sidebarTitle: "Webhooks" -description: "Python XDK WebhooksClient reference — 8 methods for X API v2 Webhooks endpoints." +description: "Methods for X API v2 Webhooks endpoints." --- Access **Webhooks** endpoints via `client.webhooks` (`WebhooksClient`). diff --git a/xdks/python/reference/overview.mdx b/xdks/python/reference/overview.mdx index 76db919ad..7b00e74b0 100644 --- a/xdks/python/reference/overview.mdx +++ b/xdks/python/reference/overview.mdx @@ -1,17 +1,17 @@ --- -title: "Python XDK API Reference" +title: "API Reference" sidebarTitle: "Overview" -description: "Complete API reference for the official Python XDK (xdk v0.11.2) across all X API v2 resource clients." +description: "Client and method reference for the Python XDK (xdk v0.11.2)." --- -The official **Python XDK** (`xdk`, `v0.11.2`) provides typed resource clients, authentication helpers, automatic pagination, and real-time streaming for the X API v2. +Client setup and method reference for `xdk` `v0.11.2`. - - Install `xdk` (`v0.11.2`) — requires Python 3.8+. + + `xdk` `v0.11.2` · Python 3.8+ - - Source code, release notes, and issue tracker for `xdk`. + + Source code and issues. @@ -49,7 +49,7 @@ client = Client(bearer_token=os.environ["X_BEARER_TOKEN"]) Maximum retry attempts for transient network or 5xx failures. -## Resource Clients +## Clients | Resource | Accessor | Client Class | Operations | | :--- | :--- | :--- | ---: | diff --git a/xdks/python/streaming.mdx b/xdks/python/streaming.mdx index fab334410..24f31163e 100644 --- a/xdks/python/streaming.mdx +++ b/xdks/python/streaming.mdx @@ -1,95 +1,95 @@ --- title: Streaming sidebarTitle: Streaming - -description: "The X API supports real-time data via endpoints like the Filtered Stream Endpoint, delivering matching Posts as they occur. This requires making a persistent." +description: Consume real-time X API v2 streams and manage filtered stream rules in Python. --- -The X API supports real-time data via endpoints like the [Filtered Stream Endpoint](https://docs.x.com/x-api/posts/filtered-stream/introduction), delivering matching Posts as they occur. This requires making a persistent http connection. -## Setup and Basic Streaming -### Synchronous + +Streaming methods on `client.stream` hold open an HTTP connection and yield events as they arrive. + +## Filtered stream + +Make sure you have added at least one rule before connecting to `client.stream.posts()`: + ```python +import os from xdk import Client -# Initialize client -client = Client(bearer_token="your_bearer_token") -# Stream posts (make sure you have rules set up first) -for post_response in client.stream.posts(): - data = post_response.model_dump() if hasattr(post_response, 'model_dump') else dict(post_response) - if 'data' in data and data['data']: - tweet = data['data'] - post_text = tweet.get('text', '') if isinstance(tweet, dict) else (tweet.text if hasattr(tweet, 'text') else '') - print(f"Post: {post_text}") + +client = Client(bearer_token=os.environ["X_BEARER_TOKEN"]) + +for event in client.stream.posts(): + if event.data: + print(event.data) ``` -### Async -```python title="Example" expandable lines wrap icon="python" + +### Using with `asyncio` + +```python import asyncio -from asyncio import Queue +import os import threading from xdk import Client + async def stream_posts_async(client: Client): - queue = Queue() - loop = asyncio.get_event_loop() + queue = asyncio.Queue() + loop = asyncio.get_running_loop() stop = threading.Event() + def run_stream(): for post in client.stream.posts(): if stop.is_set(): break asyncio.run_coroutine_threadsafe(queue.put(post), loop) asyncio.run_coroutine_threadsafe(queue.put(None), loop) + threading.Thread(target=run_stream, daemon=True).start() + while True: post = await queue.get() if post is None: break - data = post.model_dump() - if 'data' in data and data['data']: - print(f"Post: {data['data'].get('text', '')}") + if post.data: + print(post.data) stop.set() + async def main(): - client = Client(bearer_token="your_bearer_token") + client = Client(bearer_token=os.environ["X_BEARER_TOKEN"]) await stream_posts_async(client) + asyncio.run(main()) ``` -## Rule Management -Rules define filters on what specific data you are looking for(e.g. keywords, users etc). You can learn more about how to build rules using [this guide](https://docs.x.com/x-api/posts/filtered-stream/integrate/build-a-rule) -**Adding Rules**: + +## Managing rules + +Add rules: + ```python from xdk.stream.models import UpdateRulesRequest -# Add a rule -add_rules = { - "add": [ - {"value": "from:xdevelopers", "tag": "official_updates"} - ] -} -request_body = UpdateRulesRequest(**add_rules) -response = client.stream.update_rules(body=request_body) + +request_body = UpdateRulesRequest( + add=[{"value": "from:XDevelopers", "tag": "official_updates"}] +) +client.stream.update_rules(body=request_body) ``` -**Deleting Rules**: + +Delete rules: + ```python from xdk.stream.models import UpdateRulesRequest -delete_rules = { - "delete": { - "ids": ["rule_id_1", "rule_id_2"] - } -} -request_body = UpdateRulesRequest(**delete_rules) -response = client.stream.update_rules(body=request_body) + +request_body = UpdateRulesRequest( + delete={"ids": ["rule_id_1", "rule_id_2"]} +) +client.stream.update_rules(body=request_body) ``` -**Listing Rules**: + +List active rules: + ```python -# get_rules returns an Iterator, so iterate over it for page in client.stream.get_rules(): if page.data: for rule in page.data: - # Access rule attributes - Pydantic models support both attribute and dict access - rule_id = rule.id if hasattr(rule, 'id') else rule.get('id', '') - rule_value = rule.value if hasattr(rule, 'value') else rule.get('value', '') - rule_tag = rule.tag if hasattr(rule, 'tag') else rule.get('tag', '') - print(f"ID: {rule_id}, Value: {rule_value}, Tag: {rule_tag}") - break # Remove break to get all pages + print(rule.id, rule.value, rule.tag) + break ``` -For full rule syntax, see [Build a Rule](/x-api/posts/filtered-stream/integrate/build-a-rule). -## Troubleshooting -- **403 Forbidden**: Invalid auth or insufficient permissions. -- **420 / 429 Rate Limited**: Back off exponentially before reconnecting. -- **No Data**: Check rules with `get_rules()`; ensure matching Posts exist. -For detailed code examples using the Python XDK, check out the [xdk-python repository](https://github.com/xdevplatform/xdk-python) and [Python XDK Client Reference](/xdks/python/reference/clients/stream). + +See [Build a Rule](/x-api/posts/filtered-stream/integrate/build-a-rule) for rule syntax and operators, and the [StreamClient reference](/xdks/python/reference/clients/stream) for all streaming methods. diff --git a/xdks/typescript/authentication.mdx b/xdks/typescript/authentication.mdx index 44ec607ad..082c1a481 100644 --- a/xdks/typescript/authentication.mdx +++ b/xdks/typescript/authentication.mdx @@ -1,223 +1,140 @@ --- -title: "Authentication" -sidebarTitle: "Authentication" - -description: "The TypeScript SDK supports multiple authentication methods for different use cases. For read-only operations and public data access: For legacy applications." +title: Authentication +sidebarTitle: Authentication +description: Configure Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a in the TypeScript XDK. --- -The TypeScript SDK supports multiple authentication methods for different use cases. +`Client` supports Bearer Token (app-only), OAuth 2.0 with PKCE (user context), and OAuth 1.0a (user context). Get your credentials from the [X Developer Console](https://console.x.com). -## Bearer Token (App-Only Auth) +## Bearer Token -For read-only operations and public data access: +For public read, search, and streaming endpoints: -```typescript title="quickstart.ts" lines wrap icon="square-js" theme={null} -import { - Client, - type ClientConfig, - type Users -} from '@xdevplatform/xdk'; - -const config: ClientConfig = { bearerToken: 'your-bearer-token' }; - -const client: Client = new Client(config); +```typescript title="bearer.ts" lines wrap icon="square-js" theme={null} +import { Client, type ClientConfig, type Users } from "@xdevplatform/xdk"; -async function main(): Promise { - const userResponse: Users.GetByUsernameResponse = await client.users.getByUsername('XDevelopers'); - const username: string = userResponse.data?.username!; - console.log(username); -} +const config: ClientConfig = { bearerToken: process.env.X_BEARER_TOKEN }; +const client = new Client(config); -main(); +const userResponse: Users.GetByUsernameResponse = + await client.users.getByUsername("XDevelopers"); +console.log(userResponse.data?.username); ``` -```javascript quickstart.js theme={null} -import { Client } from '@xdevplatform/xdk'; +```javascript title="bearer.js" theme={null} +import { Client } from "@xdevplatform/xdk"; -const client = new Client({ bearerToken: 'your-bearer-token' }); +const client = new Client({ bearerToken: process.env.X_BEARER_TOKEN }); -const userResponse = await client.users.getByUsername('XDevelopers'); -const username = userResponse.data.username; -console.log(username); +const userResponse = await client.users.getByUsername("XDevelopers"); +console.log(userResponse.data?.username); ``` -## OAuth 1.0a (User Context) +## OAuth 2.0 with PKCE -For legacy applications or specific use cases: +For user-authorized actions (creating posts, bookmarks, DMs, X Chat): -```typescript title="oauth1.ts" expandable lines wrap icon="square-js" theme={null} -import { - Client, - OAuth1, - type OAuth1Config, - type ClientConfig, - type Users -} from '@xdevplatform/xdk'; - -const oauth1Config: OAuth1Config = { - apiKey: 'your-api-key', - apiSecret: 'your-api-secret', - accessToken: 'user-access-token', - accessTokenSecret: 'user-access-token-secret' -}; - -const oauth1: OAuth1 = new OAuth1(oauth1Config); - -const config: ClientConfig = { - oauth1: oauth1, +```typescript title="oauth2.ts" expandable lines wrap icon="square-js" theme={null} +import { + Client, + OAuth2, + generateCodeVerifier, + generateCodeChallenge, + type OAuth2Config, + type OAuth2Token, +} from "@xdevplatform/xdk"; + +const oauth2Config: OAuth2Config = { + clientId: process.env.X_CLIENT_ID!, + clientSecret: process.env.X_CLIENT_SECRET, + redirectUri: "http://localhost:8080/callback", + scope: ["tweet.read", "users.read", "offline.access"], }; -const client: Client = new Client(config); - -async function main(): Promise { - const response: Users.GetMeResponse = await client.users.getMe(); +const oauth2 = new OAuth2(oauth2Config); - const me = response.data; - console.log(me); -} +const codeVerifier = generateCodeVerifier(); +const codeChallenge = await generateCodeChallenge(codeVerifier); +oauth2.setPkceParameters(codeVerifier, codeChallenge); -main(); +const authUrl = await oauth2.getAuthorizationUrl("example-state"); +// Direct the user to authUrl and read the `code` query param from the callback +const tokens: OAuth2Token = await oauth2.exchangeCode(authCode, codeVerifier); +const client = new Client({ accessToken: tokens.access_token }); ``` -```javascript title="oauth1.js" lines wrap icon="square-js" theme={null} -import { Client, OAuth1 } from '@xdevplatform/xdk'; +```javascript title="oauth2.js" expandable lines wrap icon="square-js" theme={null} +import { + Client, + OAuth2, + generateCodeVerifier, + generateCodeChallenge, +} from "@xdevplatform/xdk"; -const oauth1 = new OAuth1({ - apiKey: 'your-api-key', - apiSecret: 'your-api-secret', - accessToken: 'user-access-token', - accessTokenSecret: 'user-access-token-secret' +const oauth2 = new OAuth2({ + clientId: process.env.X_CLIENT_ID, + clientSecret: process.env.X_CLIENT_SECRET, + redirectUri: "http://localhost:8080/callback", + scope: ["tweet.read", "users.read", "offline.access"], }); -const client = new Client({ oauth1: oauth1 }); +const codeVerifier = generateCodeVerifier(); +const codeChallenge = await generateCodeChallenge(codeVerifier); +oauth2.setPkceParameters(codeVerifier, codeChallenge); -const response = await client.users.getMe(); -const me = response.data; -console.log(me); +const authUrl = await oauth2.getAuthorizationUrl("example-state"); +const tokens = await oauth2.exchangeCode(authCode, codeVerifier); +const client = new Client({ accessToken: tokens.access_token }); +const me = await client.users.getMe(); +console.log(me.data); ``` -## OAuth 2.0 (User Context) +## OAuth 1.0a -For user-specific operations: +For OAuth 1.0a HMAC-SHA1 user context: -```typescript title="oauth2.ts" expandable lines wrap icon="square-js" theme={null} -import { - Client, - OAuth2, - generateCodeVerifier, - generateCodeChallenge, - type OAuth2Config, - type ClientConfig, - type OAuth2Token -} from '@xdevplatform/xdk'; - -(async (): Promise => { - const oauth2Config: OAuth2Config = { - clientId: 'your-client-id', - clientSecret: 'your-client-secret', - redirectUri: 'https://example.com', - scope: ['tweet.read', 'users.read', 'offline.access'], - }; - - const oauth2: OAuth2 = new OAuth2(oauth2Config); - - const state: string = 'example-state'; - const codeVerifier: string = generateCodeVerifier(); - const codeChallenge: string = await generateCodeChallenge(codeVerifier); - - oauth2.setPkceParameters(codeVerifier, codeChallenge); - - const authUrl: string = await oauth2.getAuthorizationUrl(state); - - // User visits authUrl and authorizes the app - // After authorization, user is redirected back with a code parameter - // Extract the code from the callback URL (e.g., from query params) - const authCode: string = 'code-from-callback-url'; // Replace with actual code from OAuth callback - - const tokens: OAuth2Token = await oauth2.exchangeCode(authCode, codeVerifier); - - const config: ClientConfig = { - accessToken: tokens.access_token, - }; - - const client: Client = new Client(config); -}); - -``` - -```javascript title="oauth2.js" expandable lines wrap icon="square-js" theme={null} -import { Client, OAuth2, generateCodeVerifier, generateCodeChallenge } from '@xdevplatform/xdk'; - -(async () => { - const oauth2 = new OAuth2({ - clientId: 'your-client-id', - clientSecret: 'your-client-secret', - redirectUri: 'https://example.com', - scope: ['tweet.read', 'users.read', 'offline.access'], - }); - - const state = 'example-state'; - const codeVerifier = generateCodeVerifier(); - const codeChallenge = await generateCodeChallenge(codeVerifier); - oauth2.setPkceParameters(codeVerifier, codeChallenge); - const authUrl = await oauth2.getAuthorizationUrl(state); - - // User visits authUrl and authorizes the app - // After authorization, user is redirected back with a code parameter - // Extract the code from the callback URL (e.g., from query params) - const authCode = 'code-from-callback-url'; // Replace with actual code from OAuth callback - - const tokens = await oauth2.exchangeCode(authCode, codeVerifier); - - const client = new Client({ accessToken: tokens.access_token }); - - const response = await client.users.getMe(); - const me = response.data; - console.log(me); -}); -``` - - - -## Environment Variables +```typescript title="oauth1.ts" expandable lines wrap icon="square-js" theme={null} +import { Client, OAuth1, type OAuth1Config, type Users } from "@xdevplatform/xdk"; -Store sensitive credentials in environment variables: +const oauth1Config: OAuth1Config = { + apiKey: process.env.X_API_KEY!, + apiSecret: process.env.X_API_SECRET!, + accessToken: process.env.X_ACCESS_TOKEN!, + accessTokenSecret: process.env.X_ACCESS_TOKEN_SECRET!, +}; -```bash -# .env -X_API_BEARER_TOKEN=your-bearer-token -X_API_CLIENT_ID=your-client-id -X_API_CLIENT_SECRET=your-client-secret +const client = new Client({ oauth1: new OAuth1(oauth1Config) }); +const response: Users.GetMeResponse = await client.users.getMe(); +console.log(response.data); ``` - - -```typescript env.ts theme={null} -import { Client } from '@xdevplatform/xdk'; - -const client = new Client({ bearerToken: process.env.X_API_BEARER_TOKEN }); -``` +```javascript title="oauth1.js" lines wrap icon="square-js" theme={null} +import { Client, OAuth1 } from "@xdevplatform/xdk"; -```javascript env.js theme={null} -import { Client } from '@xdevplatform/xdk'; +const oauth1 = new OAuth1({ + apiKey: process.env.X_API_KEY, + apiSecret: process.env.X_API_SECRET, + accessToken: process.env.X_ACCESS_TOKEN, + accessTokenSecret: process.env.X_ACCESS_TOKEN_SECRET, +}); -const client = new Client({ bearerToken: process.env.X_API_BEARER_TOKEN }); +const client = new Client({ oauth1 }); +const response = await client.users.getMe(); +console.log(response.data); ``` - -For detailed code examples using the Javascript/TypeScript XDK, check out our [code samples GitHub repo](https://github.com/xdevplatform/samples/tree/main/javascript). - +See the [TypeScript samples repo](https://github.com/xdevplatform/samples/tree/main/typescript) for more examples. diff --git a/xdks/typescript/install.mdx b/xdks/typescript/install.mdx index f7a995593..4af382864 100644 --- a/xdks/typescript/install.mdx +++ b/xdks/typescript/install.mdx @@ -1,12 +1,10 @@ --- -title: Install TypeScript XDK +title: Install sidebarTitle: Install -description: Install the official TypeScript and JavaScript SDK (@xdevplatform/xdk) from npm, pnpm, yarn, or bun for Node.js 18+. +description: Install the TypeScript XDK with npm, pnpm, yarn, or bun. --- -Install `@xdevplatform/xdk` from [npm](https://www.npmjs.com/package/@xdevplatform/xdk). - -## Package Managers +Install `@xdevplatform/xdk` from [npm](https://www.npmjs.com/package/@xdevplatform/xdk). Requires Node.js 18+. @@ -28,14 +26,9 @@ bun add @xdevplatform/xdk -## Requirements - -- **Node.js 18+** (uses built-in `fetch` and Web Crypto) -- **TypeScript 5.0+** (optional; bundled `.d.ts` declarations are included out of the box) - ## ESM and CommonJS -`@xdevplatform/xdk` ships dual module entrypoints: +Both module formats are included along with TypeScript `.d.ts` declarations: @@ -49,8 +42,8 @@ const { Client } = require("@xdevplatform/xdk"); -## Next Steps +## Next steps -- [Quickstart](/xdks/typescript/quickstart) — Make your first request -- [Authentication](/xdks/typescript/authentication) — Configure Bearer Token, OAuth 2.0 PKCE, or OAuth 1.0a -- [API Reference](/xdks/typescript/reference/overview) — Explore all 24 resource clients +- [Quickstart](/xdks/typescript/quickstart) +- [Authentication](/xdks/typescript/authentication) +- [API Reference](/xdks/typescript/reference/overview) diff --git a/xdks/typescript/llms.txt b/xdks/typescript/llms.txt index d6e8fb2cb..14b6801a1 100644 --- a/xdks/typescript/llms.txt +++ b/xdks/typescript/llms.txt @@ -1,19 +1,19 @@ # TypeScript XDK (`@xdevplatform/xdk` v0.7.2) -> Official TypeScript SDK for the X API v2 (Node.js 18+ (ESM & CommonJS)). Install with `npm install @xdevplatform/xdk`. +> Official TypeScript client library for the X API v2 (Node.js 18+ (ESM & CommonJS)). Install with `npm install @xdevplatform/xdk`. ## Guides -- [TypeScript overview](https://docs.x.com/xdks/typescript/overview.md): Architecture, capabilities, and client overview -- [TypeScript install](https://docs.x.com/xdks/typescript/install.md): Package installation and runtime requirements -- [TypeScript quickstart](https://docs.x.com/xdks/typescript/quickstart.md): First authenticated X API v2 request in under 2 minutes -- [TypeScript authentication](https://docs.x.com/xdks/typescript/authentication.md): Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a user-context setup -- [TypeScript pagination](https://docs.x.com/xdks/typescript/pagination.md): Automatic cursor iteration across multi-page endpoints -- [TypeScript streaming](https://docs.x.com/xdks/typescript/streaming.md): Real-time event streams with reconnection and lifecycle handling +- [TypeScript overview](https://docs.x.com/xdks/typescript/overview.md): Overview and quick example +- [TypeScript install](https://docs.x.com/xdks/typescript/install.md): Installation and requirements +- [TypeScript quickstart](https://docs.x.com/xdks/typescript/quickstart.md): Make your first X API v2 request +- [TypeScript authentication](https://docs.x.com/xdks/typescript/authentication.md): Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a +- [TypeScript pagination](https://docs.x.com/xdks/typescript/pagination.md): Cursor pagination across multi-page endpoints +- [TypeScript streaming](https://docs.x.com/xdks/typescript/streaming.md): Real-time event streams and filtered stream rules ## Client Reference -- [Reference Overview](https://docs.x.com/xdks/typescript/reference/overview.md): Main client options and resource client directory +- [Reference Overview](https://docs.x.com/xdks/typescript/reference/overview.md): Client options and client list - [`AccountClient` (Account)](https://docs.x.com/xdks/typescript/reference/clients/account.md): 2 methods via `client.account` - [`AccountActivityClient` (Account Activity)](https://docs.x.com/xdks/typescript/reference/clients/account-activity.md): 5 methods via `client.accountActivity` - [`ActivityClient` (Activity)](https://docs.x.com/xdks/typescript/reference/clients/activity.md): 5 methods via `client.activity` diff --git a/xdks/typescript/overview.mdx b/xdks/typescript/overview.mdx index 2c39d2c52..5f778edbd 100644 --- a/xdks/typescript/overview.mdx +++ b/xdks/typescript/overview.mdx @@ -1,29 +1,21 @@ --- title: TypeScript XDK sidebarTitle: Overview -description: Official TypeScript and JavaScript SDK (@xdevplatform/xdk) for the X API v2 with full type definitions, OAuth 2.0 PKCE, pagination, and event-driven streaming. +description: TypeScript and JavaScript client library for the X API v2. --- -The **TypeScript XDK** (`@xdevplatform/xdk`) is X's official TypeScript and JavaScript client library for the X API v2, shipping dual ESM and CommonJS bundles with complete TypeScript definitions. +`@xdevplatform/xdk` is the official TypeScript and JavaScript SDK for the X API v2. It ships ESM and CommonJS builds with TypeScript types, OAuth helpers, paginators, and streaming. - - `npm install @xdevplatform/xdk` — Node.js 18+. + + `npm install @xdevplatform/xdk` · Node.js 18+ - - Source code, release notes, and issue tracker. + + Source code and issues. -## Key Features - -- **Full Type Safety**: Strongly typed request bodies, option interfaces, and response schemas generated from OpenAPI. -- **Authentication**: Bearer Token (app-only), OAuth 2.0 User Context with PKCE, and OAuth 1.0a HMAC-SHA1 signing. -- **Smart Pagination**: `Paginator`, `PostPaginator`, `UserPaginator`, and `EventPaginator` with `for await (...)` support. -- **Event-Driven Streaming**: `EventDrivenStream` supporting both `.on('data', ...)` listeners and `for await (const event of stream)`. -- **Dual Module Format**: Native ESM (`import`) and CommonJS (`require`) builds for Node.js 18+ and modern runtimes. - -## Quick Example +## Quick example ```typescript import { Client } from "@xdevplatform/xdk"; @@ -36,25 +28,25 @@ const userResponse = await client.users.getByUsername("XDevelopers", { console.log(userResponse.data); ``` -## Guides & Reference +## Guides Install with npm, pnpm, yarn, or bun. - Make your first typed X API v2 request. + Make your first request. - Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a setup. + Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a. - Async iteration with typed paginators. + Async iteration and manual paging. - Real-time streams with events and async iteration. + Event listeners and async iteration. - - Full method & parameter reference for all 24 clients. + + Methods and parameters for each client. diff --git a/xdks/typescript/pagination.mdx b/xdks/typescript/pagination.mdx index a3c644c48..1d32c9e44 100644 --- a/xdks/typescript/pagination.mdx +++ b/xdks/typescript/pagination.mdx @@ -1,49 +1,47 @@ --- -title: "Pagination" -sidebarTitle: "Pagination" -description: "Paginate X API responses in TypeScript using UserPaginator and generic paginator utilities with manual fetchNext loops or async iteration for any list endpoint." +title: Pagination +sidebarTitle: Pagination +description: Paginate X API v2 responses in TypeScript with Paginator classes or manual tokens. --- -The SDK provides generic paginator utilities you can use with any endpoint that returns paginated responses. Methods return plain responses; you wrap them with a paginator. +Client methods return a single page response. Wrap any paginated call with `UserPaginator`, `PostPaginator`, `EventPaginator`, or the base `Paginator` to follow `next_token` automatically. -### Basic Pagination +## Setup -```typescript title="quick-start.ts" lines wrap icon="square-js" theme={null} -import { Client, UserPaginator, PaginatedResponse, Schemas } from '@xdevplatform/xdk'; +```typescript title="paginator.ts" lines wrap icon="square-js" theme={null} +import { Client, UserPaginator, PaginatedResponse, Schemas } from "@xdevplatform/xdk"; -const client: Client = new Client({ bearerToken: 'your-bearer-token' }); +const client = new Client({ bearerToken: process.env.X_BEARER_TOKEN }); -// Wrap any list endpoint with proper typing -const followers: UserPaginator = new UserPaginator( +const followers = new UserPaginator( async (token?: string): Promise> => { - const res = await client.users.getFollowers('', { + const res = await client.users.getFollowers("2244994945", { maxResults: 100, paginationToken: token, - userFields: ['id','name','username'], + userFields: ["id", "name", "username"], }); - return { - data: res.data ?? [], - meta: res.meta, - includes: res.includes, - errors: res.errors + return { + data: res.data ?? [], + meta: res.meta, + includes: res.includes, + errors: res.errors, }; } ); ``` -```javascript title="quick-start.js" lines wrap icon="square-js" theme={null} -import { Client } from '@xdevplatform/xdk'; -import { UserPaginator } from '@xdevplatform/xdk'; +```javascript title="paginator.js" lines wrap icon="square-js" theme={null} +import { Client, UserPaginator } from "@xdevplatform/xdk"; -const client = new Client({ bearerToken: 'your-bearer-token' }); +const client = new Client({ bearerToken: process.env.X_BEARER_TOKEN }); const followers = new UserPaginator(async (token) => { - const res = await client.users.getFollowers('', { + const res = await client.users.getFollowers("2244994945", { maxResults: 100, paginationToken: token, - userFields: ['id','name','username'], + userFields: ["id", "name", "username"], }); return { data: res.data ?? [], meta: res.meta, includes: res.includes, errors: res.errors }; }); @@ -51,41 +49,13 @@ const followers = new UserPaginator(async (token) => { -### Manual paging - - - -```typescript manual.ts theme={null} -import { UserPaginator, Schemas } from '@xdevplatform/xdk'; - -await followers.fetchNext(); // first page -while (!followers.done) { - await followers.fetchNext(); // subsequent pages -} - -const userCount: number = followers.users.length; // all fetched users -const firstUser: Schemas.User | undefined = followers.users[0]; -const nextToken: string | undefined = followers.meta?.nextToken; -``` - -```javascript manual.js theme={null} -await followers.fetchNext(); -while (!followers.done) await followers.fetchNext(); -console.log(followers.items.length); -``` - - - -### Async iteration +## Async iteration ```typescript async.ts theme={null} -import { Schemas } from '@xdevplatform/xdk'; - for await (const user of followers) { - const typedUser: Schemas.User = user; - console.log(typedUser.username); // fully typed access + console.log(user.username); } ``` @@ -97,70 +67,43 @@ for await (const user of followers) { -### Next page as a new instance +## Manual paging -```typescript next.ts theme={null} -import { UserPaginator } from '@xdevplatform/xdk'; - -await followers.fetchNext(); -if (!followers.done) { - const page2: UserPaginator = await followers.next(); // independent paginator starting at next page - await page2.fetchNext(); - console.log(page2.users.length); // items from second page +```typescript manual.ts theme={null} +await followers.fetchNext(); // first page +while (!followers.done) { + await followers.fetchNext(); // subsequent pages } + +console.log(followers.users.length); ``` -```javascript next.js theme={null} +```javascript manual.js theme={null} await followers.fetchNext(); -if (!followers.done) { - const page2 = await followers.next(); - await page2.fetchNext(); +while (!followers.done) { + await followers.fetchNext(); } +console.log(followers.items.length); ``` -### Error handling and rate limits - - +## Error handling ```typescript title="errors.ts" lines wrap icon="square-js" theme={null} -import { UserPaginator, Schemas } from '@xdevplatform/xdk'; - try { - for await (const item of followers) { - const user: Schemas.User = item; - // process user... + for await (const user of followers) { + console.log(user.username); } } catch (err: unknown) { if (followers.rateLimited) { - console.error('Rate limited, backoff required'); - // backoff / retry later - } else { - console.error('Pagination error:', err); - throw err; - } -} -``` - -```javascript errors.js theme={null} -try { - for await (const item of followers) { - // ... - } -} catch (err) { - if (followers.rateLimited) { - // backoff / retry later + console.error("Rate limited, retry after backoff"); } else { throw err; } } ``` - - - -For detailed code examples using the Javascript/TypeScript XDK, check out our [code samples GitHub repo](https://github.com/xdevplatform/samples/tree/main/javascript). - +See the [TypeScript samples repo](https://github.com/xdevplatform/samples/tree/main/typescript) for more examples. diff --git a/xdks/typescript/quickstart.mdx b/xdks/typescript/quickstart.mdx index bd4226a94..35b8ccf8e 100644 --- a/xdks/typescript/quickstart.mdx +++ b/xdks/typescript/quickstart.mdx @@ -1,26 +1,24 @@ --- -title: TypeScript Quickstart +title: Quickstart sidebarTitle: Quickstart -description: Make your first X API v2 request in TypeScript or JavaScript using @xdevplatform/xdk and a Bearer Token. +description: Make your first X API v2 request with the TypeScript XDK. --- -Make your first authenticated X API v2 call with `@xdevplatform/xdk` in under two minutes. - ```bash npm install @xdevplatform/xdk ``` - - Copy your app's **Bearer Token** from the [X Developer Console](https://console.x.com) and export it in your shell: + + Generate a **Bearer Token** in the [X Developer Console](https://console.x.com) and set it in your shell: ```bash export X_BEARER_TOKEN="your_bearer_token_here" ``` - Save the following as `quickstart.ts` (or `quickstart.mjs` for plain JavaScript): + Save this as `quickstart.ts` (or `quickstart.mjs` for JavaScript): ```typescript import { Client } from "@xdevplatform/xdk"; @@ -39,13 +37,13 @@ const posts = await client.posts.searchRecent("from:XDevelopers", { console.log("Recent posts:", posts.data); ``` - Run it with Node.js (`npx tsx quickstart.ts` or `node quickstart.mjs`). + Run it with `npx tsx quickstart.ts` or `node quickstart.mjs`. -## Next Steps +## Next steps -- [Authentication](/xdks/typescript/authentication) — Post on behalf of users with OAuth 2.0 PKCE or OAuth 1.0a -- [Pagination](/xdks/typescript/pagination) — Page through large result sets with `UserPaginator` and `PostPaginator` -- [Streaming](/xdks/typescript/streaming) — Subscribe to real-time posts with `EventDrivenStream` -- [Client Reference](/xdks/typescript/reference/overview) — Full method and option types +- [Authentication](/xdks/typescript/authentication) — Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a +- [Pagination](/xdks/typescript/pagination) — Page through results with `UserPaginator` and `PostPaginator` +- [Streaming](/xdks/typescript/streaming) — Read real-time streams with `EventDrivenStream` +- [Code samples](https://github.com/xdevplatform/samples/tree/main/typescript) — Runnable TypeScript examples diff --git a/xdks/typescript/reference/clients/account-activity.mdx b/xdks/typescript/reference/clients/account-activity.mdx index 1a4089281..c37397354 100644 --- a/xdks/typescript/reference/clients/account-activity.mdx +++ b/xdks/typescript/reference/clients/account-activity.mdx @@ -1,7 +1,7 @@ --- -title: "AccountActivityClient (TypeScript XDK)" +title: "AccountActivityClient" sidebarTitle: "Account Activity" -description: "TypeScript XDK AccountActivityClient reference — 5 methods for X API v2 Account Activity endpoints." +description: "Methods for X API v2 Account Activity endpoints." --- Access **Account Activity** endpoints via `client.accountActivity` (`AccountActivityClient`). diff --git a/xdks/typescript/reference/clients/account.mdx b/xdks/typescript/reference/clients/account.mdx index 589899566..49c82e603 100644 --- a/xdks/typescript/reference/clients/account.mdx +++ b/xdks/typescript/reference/clients/account.mdx @@ -1,7 +1,7 @@ --- -title: "AccountClient (TypeScript XDK)" +title: "AccountClient" sidebarTitle: "Account" -description: "TypeScript XDK AccountClient reference — 2 methods for X API v2 Account endpoints." +description: "Methods for X API v2 Account endpoints." --- Access **Account** endpoints via `client.account` (`AccountClient`). diff --git a/xdks/typescript/reference/clients/activity.mdx b/xdks/typescript/reference/clients/activity.mdx index e4137952a..6fb4bc0d9 100644 --- a/xdks/typescript/reference/clients/activity.mdx +++ b/xdks/typescript/reference/clients/activity.mdx @@ -1,7 +1,7 @@ --- -title: "ActivityClient (TypeScript XDK)" +title: "ActivityClient" sidebarTitle: "Activity" -description: "TypeScript XDK ActivityClient reference — 5 methods for X API v2 Activity endpoints." +description: "Methods for X API v2 Activity endpoints." --- Access **Activity** endpoints via `client.activity` (`ActivityClient`). diff --git a/xdks/typescript/reference/clients/articles.mdx b/xdks/typescript/reference/clients/articles.mdx index 6735ea25e..83f71d1d2 100644 --- a/xdks/typescript/reference/clients/articles.mdx +++ b/xdks/typescript/reference/clients/articles.mdx @@ -1,7 +1,7 @@ --- -title: "ArticlesClient (TypeScript XDK)" +title: "ArticlesClient" sidebarTitle: "Articles" -description: "TypeScript XDK ArticlesClient reference — 2 methods for X API v2 Articles endpoints." +description: "Methods for X API v2 Articles endpoints." --- Access **Articles** endpoints via `client.articles` (`ArticlesClient`). diff --git a/xdks/typescript/reference/clients/bots.mdx b/xdks/typescript/reference/clients/bots.mdx index cc5afa0b7..09ca957fa 100644 --- a/xdks/typescript/reference/clients/bots.mdx +++ b/xdks/typescript/reference/clients/bots.mdx @@ -1,7 +1,7 @@ --- -title: "BotsClient (TypeScript XDK)" +title: "BotsClient" sidebarTitle: "Bots" -description: "TypeScript XDK BotsClient reference — 6 methods for X API v2 Bots endpoints." +description: "Methods for X API v2 Bots endpoints." --- Access **Bots** endpoints via `client.bots` (`BotsClient`). diff --git a/xdks/typescript/reference/clients/broadcasts.mdx b/xdks/typescript/reference/clients/broadcasts.mdx index 6a662f9c6..1c0df7f6f 100644 --- a/xdks/typescript/reference/clients/broadcasts.mdx +++ b/xdks/typescript/reference/clients/broadcasts.mdx @@ -1,7 +1,7 @@ --- -title: "BroadcastsClient (TypeScript XDK)" +title: "BroadcastsClient" sidebarTitle: "Broadcasts" -description: "TypeScript XDK BroadcastsClient reference — 41 methods for X API v2 Broadcasts endpoints." +description: "Methods for X API v2 Broadcasts endpoints." --- Access **Broadcasts** endpoints via `client.broadcasts` (`BroadcastsClient`). diff --git a/xdks/typescript/reference/clients/calls.mdx b/xdks/typescript/reference/clients/calls.mdx index dfa4cf7d2..0296b2877 100644 --- a/xdks/typescript/reference/clients/calls.mdx +++ b/xdks/typescript/reference/clients/calls.mdx @@ -1,7 +1,7 @@ --- -title: "CallsClient (TypeScript XDK)" +title: "CallsClient" sidebarTitle: "Calls" -description: "TypeScript XDK CallsClient reference — 10 methods for X API v2 Calls endpoints." +description: "Methods for X API v2 Calls endpoints." --- Access **Calls** endpoints via `client.calls` (`CallsClient`). diff --git a/xdks/typescript/reference/clients/chat.mdx b/xdks/typescript/reference/clients/chat.mdx index 86ab96497..89d767ae9 100644 --- a/xdks/typescript/reference/clients/chat.mdx +++ b/xdks/typescript/reference/clients/chat.mdx @@ -1,7 +1,7 @@ --- -title: "ChatClient (TypeScript XDK)" +title: "ChatClient" sidebarTitle: "Chat" -description: "TypeScript XDK ChatClient reference — 45 methods for X API v2 Chat endpoints." +description: "Methods for X API v2 Chat endpoints." --- Access **Chat** endpoints via `client.chat` (`ChatClient`). diff --git a/xdks/typescript/reference/clients/communities.mdx b/xdks/typescript/reference/clients/communities.mdx index ae4639204..d66a9cf69 100644 --- a/xdks/typescript/reference/clients/communities.mdx +++ b/xdks/typescript/reference/clients/communities.mdx @@ -1,7 +1,7 @@ --- -title: "CommunitiesClient (TypeScript XDK)" +title: "CommunitiesClient" sidebarTitle: "Communities" -description: "TypeScript XDK CommunitiesClient reference — 2 methods for X API v2 Communities endpoints." +description: "Methods for X API v2 Communities endpoints." --- Access **Communities** endpoints via `client.communities` (`CommunitiesClient`). diff --git a/xdks/typescript/reference/clients/community-notes.mdx b/xdks/typescript/reference/clients/community-notes.mdx index 756f65b29..aa4bf6501 100644 --- a/xdks/typescript/reference/clients/community-notes.mdx +++ b/xdks/typescript/reference/clients/community-notes.mdx @@ -1,7 +1,7 @@ --- -title: "CommunityNotesClient (TypeScript XDK)" +title: "CommunityNotesClient" sidebarTitle: "Community Notes" -description: "TypeScript XDK CommunityNotesClient reference — 5 methods for X API v2 Community Notes endpoints." +description: "Methods for X API v2 Community Notes endpoints." --- Access **Community Notes** endpoints via `client.communityNotes` (`CommunityNotesClient`). diff --git a/xdks/typescript/reference/clients/compliance.mdx b/xdks/typescript/reference/clients/compliance.mdx index b0b338626..75a725de2 100644 --- a/xdks/typescript/reference/clients/compliance.mdx +++ b/xdks/typescript/reference/clients/compliance.mdx @@ -1,7 +1,7 @@ --- -title: "ComplianceClient (TypeScript XDK)" +title: "ComplianceClient" sidebarTitle: "Compliance" -description: "TypeScript XDK ComplianceClient reference — 6 methods for X API v2 Compliance endpoints." +description: "Methods for X API v2 Compliance endpoints." --- Access **Compliance** endpoints via `client.compliance` (`ComplianceClient`). diff --git a/xdks/typescript/reference/clients/connections.mdx b/xdks/typescript/reference/clients/connections.mdx index 0adc3edf5..9ec6b73e0 100644 --- a/xdks/typescript/reference/clients/connections.mdx +++ b/xdks/typescript/reference/clients/connections.mdx @@ -1,7 +1,7 @@ --- -title: "ConnectionsClient (TypeScript XDK)" +title: "ConnectionsClient" sidebarTitle: "Connections" -description: "TypeScript XDK ConnectionsClient reference — 4 methods for X API v2 Connections endpoints." +description: "Methods for X API v2 Connections endpoints." --- Access **Connections** endpoints via `client.connections` (`ConnectionsClient`). diff --git a/xdks/typescript/reference/clients/direct-messages.mdx b/xdks/typescript/reference/clients/direct-messages.mdx index e2e7256e2..4134df23d 100644 --- a/xdks/typescript/reference/clients/direct-messages.mdx +++ b/xdks/typescript/reference/clients/direct-messages.mdx @@ -1,7 +1,7 @@ --- -title: "DirectMessagesClient (TypeScript XDK)" +title: "DirectMessagesClient" sidebarTitle: "Direct Messages" -description: "TypeScript XDK DirectMessagesClient reference — 9 methods for X API v2 Direct Messages endpoints." +description: "Methods for X API v2 Direct Messages endpoints." --- Access **Direct Messages** endpoints via `client.directMessages` (`DirectMessagesClient`). diff --git a/xdks/typescript/reference/clients/general.mdx b/xdks/typescript/reference/clients/general.mdx index a0f40dc34..7ce45334a 100644 --- a/xdks/typescript/reference/clients/general.mdx +++ b/xdks/typescript/reference/clients/general.mdx @@ -1,7 +1,7 @@ --- -title: "GeneralClient (TypeScript XDK)" +title: "GeneralClient" sidebarTitle: "General" -description: "TypeScript XDK GeneralClient reference — 1 methods for X API v2 General endpoints." +description: "Methods for X API v2 General endpoints." --- Access **General** endpoints via `client.general` (`GeneralClient`). diff --git a/xdks/typescript/reference/clients/lists.mdx b/xdks/typescript/reference/clients/lists.mdx index 1ce556440..3de4d4b5b 100644 --- a/xdks/typescript/reference/clients/lists.mdx +++ b/xdks/typescript/reference/clients/lists.mdx @@ -1,7 +1,7 @@ --- -title: "ListsClient (TypeScript XDK)" +title: "ListsClient" sidebarTitle: "Lists" -description: "TypeScript XDK ListsClient reference — 9 methods for X API v2 Lists endpoints." +description: "Methods for X API v2 Lists endpoints." --- Access **Lists** endpoints via `client.lists` (`ListsClient`). diff --git a/xdks/typescript/reference/clients/media.mdx b/xdks/typescript/reference/clients/media.mdx index 2da57fe31..25415a861 100644 --- a/xdks/typescript/reference/clients/media.mdx +++ b/xdks/typescript/reference/clients/media.mdx @@ -1,7 +1,7 @@ --- -title: "MediaClient (TypeScript XDK)" +title: "MediaClient" sidebarTitle: "Media" -description: "TypeScript XDK MediaClient reference — 19 methods for X API v2 Media endpoints." +description: "Methods for X API v2 Media endpoints." --- Access **Media** endpoints via `client.media` (`MediaClient`). diff --git a/xdks/typescript/reference/clients/news.mdx b/xdks/typescript/reference/clients/news.mdx index 5fb4fd331..f741629a2 100644 --- a/xdks/typescript/reference/clients/news.mdx +++ b/xdks/typescript/reference/clients/news.mdx @@ -1,7 +1,7 @@ --- -title: "NewsClient (TypeScript XDK)" +title: "NewsClient" sidebarTitle: "News" -description: "TypeScript XDK NewsClient reference — 2 methods for X API v2 News endpoints." +description: "Methods for X API v2 News endpoints." --- Access **News** endpoints via `client.news` (`NewsClient`). diff --git a/xdks/typescript/reference/clients/posts.mdx b/xdks/typescript/reference/clients/posts.mdx index c7f52e702..0564a42a2 100644 --- a/xdks/typescript/reference/clients/posts.mdx +++ b/xdks/typescript/reference/clients/posts.mdx @@ -1,7 +1,7 @@ --- -title: "PostsClient (TypeScript XDK)" +title: "PostsClient" sidebarTitle: "Posts" -description: "TypeScript XDK PostsClient reference — 17 methods for X API v2 Posts endpoints." +description: "Methods for X API v2 Posts endpoints." --- Access **Posts** endpoints via `client.posts` (`PostsClient`). diff --git a/xdks/typescript/reference/clients/spaces.mdx b/xdks/typescript/reference/clients/spaces.mdx index e5db57ce3..4923a8b97 100644 --- a/xdks/typescript/reference/clients/spaces.mdx +++ b/xdks/typescript/reference/clients/spaces.mdx @@ -1,7 +1,7 @@ --- -title: "SpacesClient (TypeScript XDK)" +title: "SpacesClient" sidebarTitle: "Spaces" -description: "TypeScript XDK SpacesClient reference — 6 methods for X API v2 Spaces endpoints." +description: "Methods for X API v2 Spaces endpoints." --- Access **Spaces** endpoints via `client.spaces` (`SpacesClient`). diff --git a/xdks/typescript/reference/clients/stream.mdx b/xdks/typescript/reference/clients/stream.mdx index 9f6dee0b0..57f742297 100644 --- a/xdks/typescript/reference/clients/stream.mdx +++ b/xdks/typescript/reference/clients/stream.mdx @@ -1,7 +1,7 @@ --- -title: "StreamClient (TypeScript XDK)" +title: "StreamClient" sidebarTitle: "Stream" -description: "TypeScript XDK StreamClient reference — 18 methods for X API v2 Stream endpoints." +description: "Methods for X API v2 Stream endpoints." --- Access **Stream** endpoints via `client.stream` (`StreamClient`). diff --git a/xdks/typescript/reference/clients/trends.mdx b/xdks/typescript/reference/clients/trends.mdx index 7191f3b3c..03deeffe5 100644 --- a/xdks/typescript/reference/clients/trends.mdx +++ b/xdks/typescript/reference/clients/trends.mdx @@ -1,7 +1,7 @@ --- -title: "TrendsClient (TypeScript XDK)" +title: "TrendsClient" sidebarTitle: "Trends" -description: "TypeScript XDK TrendsClient reference — 3 methods for X API v2 Trends endpoints." +description: "Methods for X API v2 Trends endpoints." --- Access **Trends** endpoints via `client.trends` (`TrendsClient`). diff --git a/xdks/typescript/reference/clients/usage.mdx b/xdks/typescript/reference/clients/usage.mdx index b6972494a..59698585a 100644 --- a/xdks/typescript/reference/clients/usage.mdx +++ b/xdks/typescript/reference/clients/usage.mdx @@ -1,7 +1,7 @@ --- -title: "UsageClient (TypeScript XDK)" +title: "UsageClient" sidebarTitle: "Usage" -description: "TypeScript XDK UsageClient reference — 2 methods for X API v2 Usage endpoints." +description: "Methods for X API v2 Usage endpoints." --- Access **Usage** endpoints via `client.usage` (`UsageClient`). diff --git a/xdks/typescript/reference/clients/users.mdx b/xdks/typescript/reference/clients/users.mdx index 07990f381..ca50c13ce 100644 --- a/xdks/typescript/reference/clients/users.mdx +++ b/xdks/typescript/reference/clients/users.mdx @@ -1,7 +1,7 @@ --- -title: "UsersClient (TypeScript XDK)" +title: "UsersClient" sidebarTitle: "Users" -description: "TypeScript XDK UsersClient reference — 46 methods for X API v2 Users endpoints." +description: "Methods for X API v2 Users endpoints." --- Access **Users** endpoints via `client.users` (`UsersClient`). diff --git a/xdks/typescript/reference/clients/webhooks.mdx b/xdks/typescript/reference/clients/webhooks.mdx index 163ec0579..89ee12c8a 100644 --- a/xdks/typescript/reference/clients/webhooks.mdx +++ b/xdks/typescript/reference/clients/webhooks.mdx @@ -1,7 +1,7 @@ --- -title: "WebhooksClient (TypeScript XDK)" +title: "WebhooksClient" sidebarTitle: "Webhooks" -description: "TypeScript XDK WebhooksClient reference — 8 methods for X API v2 Webhooks endpoints." +description: "Methods for X API v2 Webhooks endpoints." --- Access **Webhooks** endpoints via `client.webhooks` (`WebhooksClient`). diff --git a/xdks/typescript/reference/overview.mdx b/xdks/typescript/reference/overview.mdx index cbda0ee3d..e8ebb3e39 100644 --- a/xdks/typescript/reference/overview.mdx +++ b/xdks/typescript/reference/overview.mdx @@ -1,17 +1,17 @@ --- -title: "TypeScript XDK API Reference" +title: "API Reference" sidebarTitle: "Overview" -description: "Complete API reference for the official TypeScript XDK (@xdevplatform/xdk v0.7.2) across all X API v2 resource clients." +description: "Client and method reference for the TypeScript XDK (@xdevplatform/xdk v0.7.2)." --- -The official **TypeScript XDK** (`@xdevplatform/xdk`, `v0.7.2`) provides typed resource clients, authentication helpers, automatic pagination, and real-time streaming for the X API v2. +Client setup and method reference for `@xdevplatform/xdk` `v0.7.2`. - - Install `@xdevplatform/xdk` (`v0.7.2`) — requires Node.js 18+ (ESM & CommonJS). + + `@xdevplatform/xdk` `v0.7.2` · Node.js 18+ (ESM & CommonJS) - - Source code, release notes, and issue tracker for `@xdevplatform/xdk`. + + Source code and issues. @@ -45,7 +45,7 @@ const client = new Client({ bearerToken: process.env.X_BEARER_TOKEN }); Request timeout in milliseconds. -## Resource Clients +## Clients | Resource | Accessor | Client Class | Operations | | :--- | :--- | :--- | ---: | diff --git a/xdks/typescript/streaming.mdx b/xdks/typescript/streaming.mdx index ea0f4dd9e..fb7676866 100644 --- a/xdks/typescript/streaming.mdx +++ b/xdks/typescript/streaming.mdx @@ -1,104 +1,63 @@ --- -title: "Streaming" -sidebarTitle: "Streaming" -description: "Stream real-time X API data in TypeScript using event listeners or async iteration for sampled posts, with automatic reconnection and stream lifecycle control." +title: Streaming +sidebarTitle: Streaming +description: Consume real-time X API v2 streams in TypeScript with event listeners or async iteration. --- -The TypeScript SDK provides real-time streaming capabilities for live data feeds. +Streaming methods on `client.stream` return an `EventDrivenStream` that supports both `.on(...)` event listeners and `for await`. -## Basic Streaming - -Connect to real-time sampled posts: +## Event listeners ```typescript title="stream.ts" lines wrap icon="square-js" theme={null} -import { Client } from '@xdevplatform/xdk'; +import { Client } from "@xdevplatform/xdk"; -const client: Client = new Client({ bearerToken: 'your-bearer-token' }); +const client = new Client({ bearerToken: process.env.X_BEARER_TOKEN }); -// 1% sampled public posts const stream = await client.stream.postsSample({ - tweetFields: ['id','text','created_at'], - expansions: ['author_id'], - userFields: ['id','username','name'] + tweetFields: ["id", "text", "created_at"], + expansions: ["author_id"], + userFields: ["id", "username", "name"], }); -// Listen to events -stream.on('data', (event) => { - // event is the parsed JSON line (data/includes/matching_rules) - console.log('New data:', event); +stream.on("data", (event) => { + console.log(event); }); - -stream.on('error', (e) => console.error('Stream error:', e)); -stream.on('close', () => console.log('Stream closed')); +stream.on("keepAlive", () => { + // heartbeat received +}); +stream.on("error", (err) => console.error("Stream error:", err)); +stream.on("close", () => console.log("Stream closed")); ``` -```javascript stream.js theme={null} -import { Client } from '@xdevplatform/xdk'; +```javascript title="stream.js" theme={null} +import { Client } from "@xdevplatform/xdk"; -const client = new Client({ bearerToken: 'your-bearer-token' }); -const stream = await client.stream.postsSample({ tweetFields: ['id','text'] }); +const client = new Client({ bearerToken: process.env.X_BEARER_TOKEN }); +const stream = await client.stream.postsSample({ tweetFields: ["id", "text"] }); -stream.on('data', (event) => { - console.log('New data:', event); -}); -stream.on('error', (e) => console.error('Stream error:', e)); -stream.on('close', () => console.log('Stream closed')); +stream.on("data", (event) => console.log(event)); +stream.on("error", (err) => console.error("Stream error:", err)); +stream.on("close", () => console.log("Stream closed")); ``` -## Async Iteration - -Consume the stream with async iteration: +## Async iteration - - -```typescript async.ts theme={null} +```typescript const stream = await client.stream.postsSample(); -for await (const event of stream) { - // Each event is a parsed JSON line (data/includes/matching_rules) - console.log(event); -} -``` -```javascript async.js theme={null} -const stream = await client.stream.postsSample(); for await (const event of stream) { console.log(event); } ``` - - -## Stream Management - -Control lifecycle from the event-driven stream: +## Closing a stream ```typescript -// Close the stream stream.close(); - -// Auto-reconnect (if enabled by your wrapper) -// The default EventDrivenStream exposes basic reconnect hooks -``` - -## Error Handling - -Handle streaming errors and reconnections: - -```typescript -stream.on('error', (event) => { - const err = event.error || event; - console.error('Stream error:', err); -}); - -stream.on('keepAlive', () => { - // heartbeat event -}); ``` - -For detailed code examples using the Javascript/TypeScript XDK, check out our [code samples GitHub repo](https://github.com/xdevplatform/samples/tree/main/javascript). - +See [Build a Rule](/x-api/posts/filtered-stream/integrate/build-a-rule) for Filtered Stream rules, and the [TypeScript samples repo](https://github.com/xdevplatform/samples/tree/main/typescript) for more examples.