Official Java SDK for the X API v2 (Java 17+).
<dependency>
<groupId>com.x</groupId>
<artifactId>xdk</artifactId>
<version>0.2.0</version>
</dependency>import com.x.xdk.XClient;
import com.x.xdk.XClientConfig;
import com.x.xdk.models.Schemas;
XClient client = XClient.builder()
.bearerToken(System.getenv("X_BEARER_TOKEN"))
.build();
Schemas.GetUsersByUsernameResponse user =
client.users().getByUsername("XDevelopers");
System.out.println(user.getData());- Bearer Token (App-Only):
XClient.builder().bearerToken("...").build() - OAuth 2.0 User Context & PKCE:
OAuth2Pkce+XClient.builder().oauth2(oauth2).build() - OAuth 1.0a User Context:
OAuth1+XClient.builder().oauth1(oauth1).build()
- Paginated operations have
*Pages(...)variants returningPaginator<T>(implementingIterable<T>) for automatic cursor-based iteration. - Streaming operations return
EventStream<T>(implementingIterable<T>andAutoCloseable) with incremental UTF-8 line decoding and exponential backoff reconnection.
- Runnable Use-Case Examples: See
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
mvn test-compile exec:java -Dexec.classpathScope=test -Dexec.mainClass=com.x.xdk.canary.XdkCanaryApp -Dexec.args="--once"(or--daemon --port 8790for an always-on health &/metricsprobe server against the built-in X API simulator or liveX_BEARER_TOKEN).