Skip to content

Commit bb94a1c

Browse files
lanbytescursoragent
andcommitted
Add Kotlin wrapper around the TwexAPI Java SDK.
Give Kotlin apps coroutine helpers on the same typed search, follower, DM, and automation surface. Co-authored-by: Cursor <cursoragent@cursor.com>
0 parents  commit bb94a1c

16 files changed

Lines changed: 687 additions & 0 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
workflow_dispatch:
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-java@v4
13+
with:
14+
distribution: temurin
15+
java-version: "17"
16+
- uses: gradle/actions/setup-gradle@v4
17+
- run: ./gradlew build --no-daemon

.github/workflows/publish.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
publish:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v4
9+
- uses: actions/setup-java@v4
10+
with:
11+
distribution: temurin
12+
java-version: "17"
13+
- uses: gradle/actions/setup-gradle@v4
14+
- name: Publish locally signed artifacts
15+
env:
16+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.JAVA_GPG_SECRET_KEY }}
17+
ORG_GRADLE_PROJECT_signingPassphrase: ${{ secrets.JAVA_GPG_PASSPHRASE }}
18+
run: ./gradlew publishToMavenLocal --no-daemon

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
# Ignore Gradle build output directory
4+
build
5+
bin/
6+
.idea/
7+
.DS_Store
8+
.env
9+
.env.local

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Contributing
2+
3+
This repository is a Kotlin wrapper around the generated Java SDK.
4+
Do not add generated REST client code here.
5+
6+
- Java SDK / OpenAPI changes: https://github.com/twexapi-dev/x-api-scraper-java
7+
- Kotlin helpers and docs: open an issue or PR in this repository

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 TwexAPI
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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.

build.gradle.kts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
plugins {
2+
kotlin("jvm") version "2.0.21"
3+
`java-library`
4+
`maven-publish`
5+
signing
6+
}
7+
8+
group = "io.twexapi"
9+
version = "0.1.0"
10+
11+
java {
12+
toolchain {
13+
languageVersion.set(JavaLanguageVersion.of(17))
14+
}
15+
withSourcesJar()
16+
withJavadocJar()
17+
}
18+
19+
kotlin {
20+
jvmToolchain(17)
21+
}
22+
23+
repositories {
24+
mavenLocal()
25+
mavenCentral()
26+
}
27+
28+
dependencies {
29+
api("io.twexapi:x-api-scraper:0.1.0")
30+
api("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.9.0")
31+
}
32+
33+
publishing {
34+
publications {
35+
create<MavenPublication>("maven") {
36+
from(components["java"])
37+
groupId = "io.twexapi"
38+
artifactId = "x-api-scraper-kotlin"
39+
version = project.version.toString()
40+
pom {
41+
name.set("TwexAPI Kotlin SDK")
42+
description.set("Twitter API alternative Kotlin SDK for tweet search, follower scraping, timelines, DMs, communities, lists, trending, and X automation. Wraps the Speakeasy Java client with coroutine helpers. Not affiliated with X Corp.")
43+
url.set("https://github.com/twexapi-dev/x-api-scraper-kotlin")
44+
licenses {
45+
license {
46+
name.set("The MIT License (MIT)")
47+
url.set("https://mit-license.org/")
48+
}
49+
}
50+
developers {
51+
developer {
52+
name.set("TwexAPI")
53+
organization.set("TwexAPI")
54+
email.set("support@twexapi.io")
55+
}
56+
}
57+
scm {
58+
url.set("https://github.com/twexapi-dev/x-api-scraper-kotlin")
59+
connection.set("scm:git:https://github.com/twexapi-dev/x-api-scraper-kotlin.git")
60+
}
61+
organization {
62+
name.set("TwexAPI")
63+
url.set("https://twexapi.io")
64+
}
65+
}
66+
}
67+
}
68+
}
69+
70+
signing {
71+
val signingKey: String? = findProperty("signingKey") as String?
72+
val signingPassphrase: String? = findProperty("signingPassphrase") as String?
73+
if (!signingKey.isNullOrBlank() && !signingPassphrase.isNullOrBlank()) {
74+
useInMemoryPgpKeys(signingKey, signingPassphrase)
75+
sign(publishing.publications["maven"])
76+
}
77+
}

examples/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# x-api-scraper-kotlin examples
2+
3+
Requires JDK 17+ and a TwexAPI API key from https://twexapi.io/dashboard.
4+
5+
```bash
6+
export X_API_SCRAPER_KEY=your_key
7+
./gradlew publishToMavenLocal
8+
```
9+
10+
Then use `examples/SearchAdvanced.kt` as the client pattern.

examples/SearchAdvanced.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package examples
2+
3+
import io.twexapi.sdk.kotlin.xapiScraper
4+
import io.twexapi.sdk.models.components.AdvancedSearchCursorQuery
5+
6+
// Usage:
7+
// export X_API_SCRAPER_KEY=your_key
8+
// ./gradlew publishToMavenLocal
9+
10+
fun main() {
11+
val sdk = xapiScraper()
12+
val req = AdvancedSearchCursorQuery.builder()
13+
.searchTerms(listOf("from:elonmusk"))
14+
.sortBy("Latest")
15+
.nextCursor("")
16+
.build()
17+
println(sdk.search().advanced().request(req).call())
18+
}

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
groupId=io.twexapi
2+
artifactId=x-api-scraper-kotlin
3+
version=0.1.0
4+
org.gradle.jvmargs=-Xmx2g
5+
kotlin.code.style=official

0 commit comments

Comments
 (0)