Skip to content

Repository files navigation

TwexAPI Kotlin SDK: Twitter API for search, followers, profiles & timelines

Use the TwexAPI Kotlin SDK to search tweets, scrape Twitter followers, and read X profiles, timelines, replies, and threads. Search communities, fetch lists, articles, hashtags, cashtags, and global trending tweets with typed request objects. It is a Twitter API alternative for Kotlin services and agents.

REST API | Java SDK | TypeScript SDK | Python SDK | Ruby SDK | Dashboard

This SDK wraps the Speakeasy-generated Java client with Kotlin helpers and coroutine await().

Kotlin or Java

Use this client for Kotlin coroutines and typed builders. Use the Java SDK for Java-first codebases.

Common Twitter & X tasks

Task REST Route Kotlin client
Search tweets without the X API POST /twitter/advanced_search/page sdk.search().advanced()
Search hashtags or cashtags POST /twitter/hashtags, POST /twitter/cashtags sdk.search().hashtags(), sdk.search().cashtags()
Read an X profile GET /twitter/{screen_name}/about sdk.users().getAbout()
Read a profile timeline GET /twitter/{screen_name}/timeline/page sdk.timelines().userPage()
Scrape Twitter followers POST /v3/twitter/users/followers sdk.users().followers().list()
Scrape following accounts POST /v3/twitter/users/following sdk.users().following().list()
Read tweet replies POST /twitter/tweets/{tweet_id}/replies/page sdk.replies().page()
Read a tweet thread POST /twitter/tweets/thread_by_id sdk.tweets().threadById()
Search communities POST /twitter/community/search sdk.communities().search()
Get global trending tweets GET /twitter/global-trending/tweets sdk.trending().tweets()

Package & registry trust

SDK Installation

Requires JDK 17+.

Gradle:

implementation("io.twexapi:x-api-scraper-kotlin:0.1.0")

Maven:

<dependency>
    <groupId>io.twexapi</groupId>
    <artifactId>x-api-scraper-kotlin</artifactId>
    <version>0.1.0</version>
</dependency>

Maven Central may still be catching up. Install from source:

./gradlew publishToMavenLocal

SDK Example Usage

Get an API key from the TwexAPI dashboard. Pass it as bearerAuth, or set X_API_SCRAPER_KEY.

import io.twexapi.sdk.models.components.AdvancedSearchCursorQuery
import io.twexapi.sdk.kotlin.xapiScraper

fun main() {
    val sdk = xapiScraper()

    val req = AdvancedSearchCursorQuery.builder()
        .searchTerms(listOf("from:elonmusk"))
        .sortBy("Latest")
        .nextCursor("")
        .build()

    val res = sdk.search().advanced().request(req).call()
    println(res)
}

Keep API keys out of source code, URLs, and logs.

Use Coroutines

async() returns the Java CompletableFuture client. Call await() from a coroutine:

import io.twexapi.sdk.kotlin.async
import io.twexapi.sdk.kotlin.await
import io.twexapi.sdk.kotlin.xapiScraper
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    val sdk = xapiScraper().async()
    val req = AdvancedSearchCursorQuery.builder()
        .searchTerms(listOf("from:elonmusk"))
        .sortBy("Latest")
        .nextCursor("")
        .build()

    val res = sdk.search().advanced().request(req).call().await()
    println(res)
}

Development

This library is a thin Kotlin layer over the generated Java SDK. Method surface changes belong in x-api-scraper-java.

./gradlew build

GitHub Actions can publish to Maven Central. Add these repository secrets:

  • OSSRH_USERNAME
  • OSSRH_PASSWORD
  • JAVA_GPG_SECRET_KEY
  • JAVA_GPG_PASSPHRASE

TwexAPI is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp.

About

Kotlin SDK for TwexAPI public social data and approved account workflows. Independent third-party service.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages