Skip to content

About

Official C# (.NET 8) SDK for the X API v2

Resources

Code of conduct

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

XDK C# / .NET SDK

Official C# / .NET SDK for the X API v2 (.NET 8+ with zero external runtime dependencies, and .NET Framework 4.7.2+ via netstandard2.0).

Installation

dotnet add package XDevPlatform.Xdk --version 0.5.0

.NET Framework 4.7.2+ notes

  • On netstandard2.0, the package depends on Microsoft's System.Text.Json (8.0.5), Microsoft.Bcl.AsyncInterfaces (8.0.0), and System.Threading.Tasks.Extensions (4.5.4). .NET 8+ consumers keep zero external dependencies.
  • On older Windows versions (such as Windows Server 2012 R2) or legacy AppContext TLS configurations, enable TLS 1.2 at startup:
    System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;

Quick Start

using Xdk;
using Xdk.Models;

var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN")
});

var response = await client.Users.GetByUsernameAsync("XDevelopers");
Console.WriteLine(response.Data);

Authentication

  • Bearer Token (App-Only): new XClient(new XClientOptions { BearerToken = "..." })
  • OAuth 2.0 PKCE & Refresh: OAuth2Pkce + new XClient(new XClientOptions { OAuth2 = oauth2 })
  • OAuth 1.0a User Context: OAuth1 + new XClient(new XClientOptions { OAuth1 = oauth1 })

Pagination & Streaming

  • Paginated endpoints expose *Pages(...) returning Paginator<T> (IAsyncEnumerable<T>), enabling await foreach (var page in client.Users.GetFollowersPages(id)).
  • Streaming endpoints return EventStream<T> (IAsyncEnumerable<T> and IAsyncDisposable) with incremental UTF-8 line decoding, exponential backoff reconnection, heartbeat callbacks (OnKeepAlive), ReconnectOnClose, and opt-in IdleTimeout (e.g. TimeSpan.FromSeconds(60)) to recover silently stalled connections.

Examples & Continuous Canary

  • Runnable Use-Case Examples: See examples/Xdk.Examples/ for end-to-end runnable workflows covering Posts, Search, Users, Bookmarks, Filtered & Sample Streaming, Chunked Media Upload, Direct Messages & XChat, Lists, Spaces, Communities, Community Notes, Trends, News, Webhooks, Compliance, Usage, and OAuth 1.0a / 2.0 PKCE.
  • Continuous Canary Runner: Run dotnet run --project examples/Xdk.Examples -- --canary --once (or --canary --daemon --port 8791 for an always-on /health, /status, and /metrics probe server against the built-in X API simulator or live X_BEARER_TOKEN).

About

Official C# (.NET 8) SDK for the X API v2

Resources

Code of conduct

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages