|
| 1 | +# TwexAPI Kotlin SDK: Twitter API for search, followers, DMs & X automation |
| 2 | + |
| 3 | +Use the TwexAPI Kotlin SDK to search tweets, scrape Twitter followers, and read X profiles, timelines, replies, and threads. |
| 4 | +Send DMs, search communities, fetch lists, articles, hashtags, cashtags, and global trending tweets with typed request objects. |
| 5 | +Like, retweet, follow, and post through documented REST routes. It is a Twitter API alternative for Kotlin services and agents. |
| 6 | + |
| 7 | +[REST API](https://docs.twexapi.io) | [Java SDK](https://github.com/twexapi-dev/x-api-scraper-java) | [TypeScript SDK](https://github.com/twexapi-dev/x-api-scraper-typescript) | [Python SDK](https://github.com/twexapi-dev/x-api-scraper-python) | [Ruby SDK](https://github.com/twexapi-dev/x-api-scraper-ruby) | [Dashboard](https://twexapi.io/dashboard) |
| 8 | + |
| 9 | +This SDK wraps the Speakeasy-generated Java client with Kotlin helpers and coroutine `await()`. |
| 10 | + |
| 11 | +## Kotlin or Java |
| 12 | + |
| 13 | +Use this client for Kotlin coroutines and typed builders. |
| 14 | +Use the [Java SDK](https://github.com/twexapi-dev/x-api-scraper-java) for Java-first codebases. |
| 15 | + |
| 16 | +## Common Twitter & X tasks |
| 17 | + |
| 18 | +| Task | REST Route | Kotlin client | |
| 19 | +| ------------------------------- | -------------------------------------------------- | ----------------------------------------------- | |
| 20 | +| Search tweets without the X API | `POST /twitter/advanced_search/page` | `sdk.search().advanced()` | |
| 21 | +| Search hashtags or cashtags | `POST /twitter/hashtags`, `POST /twitter/cashtags` | `sdk.search().hashtags()`, `sdk.search().cashtags()` | |
| 22 | +| Read an X profile | `GET /twitter/{screen_name}/about` | `sdk.users().getAbout()` | |
| 23 | +| Read a profile timeline | `GET /twitter/{screen_name}/timeline/page` | `sdk.timelines().userPage()` | |
| 24 | +| Scrape Twitter followers | `POST /v3/twitter/users/followers` | `sdk.users().followers().list()` | |
| 25 | +| Scrape following accounts | `POST /v3/twitter/users/following` | `sdk.users().following().list()` | |
| 26 | +| Read tweet replies | `POST /twitter/tweets/{tweet_id}/replies/page` | `sdk.replies().page()` | |
| 27 | +| Read a tweet thread | `POST /twitter/tweets/thread_by_id` | `sdk.tweets().threadById()` | |
| 28 | +| Send or read DMs | `/v3/twitter/send-dm`, `/v3/twitter/dm-history` | `sdk.dm()` | |
| 29 | +| Search communities | `POST /twitter/community/search` | `sdk.communities().search()` | |
| 30 | +| Get global trending tweets | `GET /twitter/global-trending/tweets` | `sdk.trending().tweets()` | |
| 31 | +| Post or reply | `POST /twitter/tweets/create` | `sdk.tweets().actions().create()` | |
| 32 | + |
| 33 | +## Package & registry trust |
| 34 | + |
| 35 | +- Package: `io.twexapi:x-api-scraper-kotlin` |
| 36 | +- Source: [twexapi-dev/x-api-scraper-kotlin](https://github.com/twexapi-dev/x-api-scraper-kotlin) |
| 37 | +- Java client: [io.twexapi:x-api-scraper](https://central.sonatype.com/artifact/io.twexapi/x-api-scraper) |
| 38 | +- Docs: [docs.twexapi.io](https://docs.twexapi.io) |
| 39 | +- License: MIT |
| 40 | +- Dashboard: [twexapi.io/dashboard](https://twexapi.io/dashboard) |
| 41 | + |
| 42 | +## SDK Installation |
| 43 | + |
| 44 | +Requires JDK 17+. |
| 45 | + |
| 46 | +Gradle: |
| 47 | + |
| 48 | +```kotlin |
| 49 | +implementation("io.twexapi:x-api-scraper-kotlin:0.1.0") |
| 50 | +``` |
| 51 | + |
| 52 | +Maven: |
| 53 | + |
| 54 | +```xml |
| 55 | +<dependency> |
| 56 | + <groupId>io.twexapi</groupId> |
| 57 | + <artifactId>x-api-scraper-kotlin</artifactId> |
| 58 | + <version>0.1.0</version> |
| 59 | +</dependency> |
| 60 | +``` |
| 61 | + |
| 62 | +Maven Central may still be catching up. Install from source: |
| 63 | + |
| 64 | +```bash |
| 65 | +./gradlew publishToMavenLocal |
| 66 | +``` |
| 67 | + |
| 68 | +## SDK Example Usage |
| 69 | + |
| 70 | +Get an API key from the [TwexAPI dashboard](https://twexapi.io/dashboard). Pass it as `bearerAuth`, or set `X_API_SCRAPER_KEY`. |
| 71 | + |
| 72 | +```kotlin |
| 73 | +import io.twexapi.sdk.models.components.AdvancedSearchCursorQuery |
| 74 | +import io.twexapi.sdk.kotlin.xapiScraper |
| 75 | + |
| 76 | +fun main() { |
| 77 | + val sdk = xapiScraper() |
| 78 | + |
| 79 | + val req = AdvancedSearchCursorQuery.builder() |
| 80 | + .searchTerms(listOf("from:elonmusk")) |
| 81 | + .sortBy("Latest") |
| 82 | + .nextCursor("") |
| 83 | + .build() |
| 84 | + |
| 85 | + val res = sdk.search().advanced().request(req).call() |
| 86 | + println(res) |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +Write actions (tweet, follow, like, DM send) also need a Twitter cookie or `auth_token` on the request. Pass them on the operation input. |
| 91 | + |
| 92 | +Keep API keys out of source code, URLs, and logs. |
| 93 | + |
| 94 | +## Use Coroutines |
| 95 | + |
| 96 | +`async()` returns the Java `CompletableFuture` client. Call `await()` from a coroutine: |
| 97 | + |
| 98 | +```kotlin |
| 99 | +import io.twexapi.sdk.kotlin.async |
| 100 | +import io.twexapi.sdk.kotlin.await |
| 101 | +import io.twexapi.sdk.kotlin.xapiScraper |
| 102 | +import kotlinx.coroutines.runBlocking |
| 103 | + |
| 104 | +fun main() = runBlocking { |
| 105 | + val sdk = xapiScraper().async() |
| 106 | + val req = AdvancedSearchCursorQuery.builder() |
| 107 | + .searchTerms(listOf("from:elonmusk")) |
| 108 | + .sortBy("Latest") |
| 109 | + .nextCursor("") |
| 110 | + .build() |
| 111 | + |
| 112 | + val res = sdk.search().advanced().request(req).call().await() |
| 113 | + println(res) |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +## Development |
| 118 | + |
| 119 | +This library is a thin Kotlin layer over the generated Java SDK. Method surface changes belong in [x-api-scraper-java](https://github.com/twexapi-dev/x-api-scraper-java). |
| 120 | + |
| 121 | +```bash |
| 122 | +./gradlew build |
| 123 | +``` |
| 124 | + |
| 125 | +GitHub Actions can publish to Maven Central. Add these repository secrets: |
| 126 | + |
| 127 | +- `OSSRH_USERNAME` |
| 128 | +- `OSSRH_PASSWORD` |
| 129 | +- `JAVA_GPG_SECRET_KEY` |
| 130 | +- `JAVA_GPG_PASSPHRASE` |
| 131 | + |
| 132 | +TwexAPI is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp. |
0 commit comments