Use the TwexAPI Kotlin SDK to search tweets, scrape Twitter followers, and read X profiles, timelines, replies, and threads. Send DMs, search communities, fetch lists, articles, hashtags, cashtags, and global trending tweets with typed request objects. Like, retweet, follow, and post through documented REST routes. 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().
Use this client for Kotlin coroutines and typed builders. Use the Java SDK for Java-first codebases.
| 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() |
| Send or read DMs | /v3/twitter/send-dm, /v3/twitter/dm-history |
sdk.dm() |
| Search communities | POST /twitter/community/search |
sdk.communities().search() |
| Get global trending tweets | GET /twitter/global-trending/tweets |
sdk.trending().tweets() |
| Post or reply | POST /twitter/tweets/create |
sdk.tweets().actions().create() |
- Package:
io.twexapi:x-api-scraper-kotlin - Source: twexapi-dev/x-api-scraper-kotlin
- Java client: io.twexapi:x-api-scraper
- Docs: docs.twexapi.io
- License: MIT
- Dashboard: twexapi.io/dashboard
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 publishToMavenLocalGet 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)
}Write actions (tweet, follow, like, DM send) also need a Twitter cookie or auth_token on the request. Pass them on the operation input.
Keep API keys out of source code, URLs, and logs.
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)
}This library is a thin Kotlin layer over the generated Java SDK. Method surface changes belong in x-api-scraper-java.
./gradlew buildGitHub Actions can publish to Maven Central. Add these repository secrets:
OSSRH_USERNAMEOSSRH_PASSWORDJAVA_GPG_SECRET_KEYJAVA_GPG_PASSPHRASE
TwexAPI is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp.