What You'll Learn
- • Setting up your development environment
- • Installing the required HTTP client
- • Authenticating with the ScrapeCreators API
- • Making requests to Truth Social
- • Handling responses and errors
- • Best practices for production use
Extract post data from Truth Social
Learn how to scrape Truth Social posts using Kotlin. This comprehensive guide will walk you through the entire process, from setup to implementation.
First, you'll need a ScrapeCreators API key to authenticate your requests.
Sign up at app.scrapecreators.com to get your free API key with 100 requests.
Make sure you have the following installed:
OkHttp is an HTTP client for Kotlin/Java
implementation "com.squareup.okhttp3:okhttp:4.9.3"
Now let's make a request to the Truth Social API using Kotlin. Replace YOUR_API_KEY
with your actual API key.
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.net.URI
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
class Scraper {
companion object {
private const val API_KEY = "YOUR_API_KEY"
private const val BASE_URL = "https://api.scrapecreators.com"
private const val ENDPOINT_PATH = "/v1/truthsocial/post"
@JvmStatic
fun main(args: Array<String>) {
try {
val result = scrape()
println("Response: $result")
} catch (e: Exception) {
println("Error: ${e.message}")
}
}
fun scrape(): String {
val client = HttpClient.newHttpClient()
// Build query parameters
val params = mapOf(
"url" to "https://truthsocial.com/@realDonaldTrump/posts/114315219437063160"
)
val queryString = params.entries.joinToString("&") { (key, value) ->
"${key}=${URLEncoder.encode(value, StandardCharsets.UTF_8)}"
}
val url = "${BASE_URL}${ENDPOINT_PATH}?${queryString}"
val request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-api-key", API_KEY)
.header("Accept", "application/json")
.GET()
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
if (response.statusCode() == 200) {
return response.body()
} else {
throw RuntimeException("HTTP ${response.statusCode()}: ${response.body()}")
}
}
}
}
This endpoint accepts the following parameters:
url
Required(string)Truth Social post URL
Example: https://truthsocial.com/@realDonaldTrump/posts/114315219437063160
Execute your script to test the API connection. You should see a JSON response with Truth Social posts data.
✅ Success: You should receive a structured JSON response containing the requested data.
Here's an example of the JSON response you'll receive:
{
"success": true,
"text": "It’s so hard to watch as Highly Qualified and Respected Ambassadors, who we desperately need representing our Country in Faraway Lands, are purposefully meant to wait as the Democrat Senators take maximum time for every single one of them, even though they were confirmed with Bipartisan Support, also at maximum time, and only done to hurt our Country. A process that should take a matter of minutes is forced into taking months, making it very hard on the new Ambassadors’ families, and not good, at all, for the Good Ole’ U.S.A. In a true sense, in numerous cases, what they do is actually a Threat to National Security. John Thune and the Republicans are doing a great job, but nothing much can be done when the Democrats make everyone sit, day after day, pushing the limits. The level of hostility is not to be believed!",
"id": "114315219437063160",
"created_at": "2025-04-10T19:03:40.023Z",
"in_reply_to_id": null,
"quote_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
"spoiler_text": "",
"visibility": "public",
"language": "en",
"uri": "https://truthsocial.com/@realDonaldTrump/114315219437063160",
"url": "https://truthsocial.com/@realDonaldTrump/114315219437063160",
"content": "<p>It’s so hard to watch as Highly Qualified and Respected Ambassadors, who we desperately need representing our Country in Faraway Lands, are purposefully meant to wait as the Democrat Senators take maximum time for every single one of them, even though they were confirmed with Bipartisan Support, also at maximum time, and only done to hurt our Country. A process that should take a matter of minutes is forced into taking months, making it very hard on the new Ambassadors’ families, and not good, at all, for the Good Ole’ U.S.A. In a true sense, in numerous cases, what they do is actually a Threat to National Security. John Thune and the Republicans are doing a great job, but nothing much can be done when the Democrats make everyone sit, day after day, pushing the limits. The level of hostility is not to be believed!</p>",
"account": {
"id": "107780257626128497",
"username": "realDonaldTrump",
"acct": "realDonaldTrump",
"display_name": "Donald J. Trump",
"locked": false,
"bot": false,
"discoverable": false,
"group": false,
"created_at": "2022-02-11T16:16:57.705Z",
"note": "<p></p>",
"url": "https://truthsocial.com/@realDonaldTrump",
"avatar": "https://static-assets-1.truthsocial.com/tmtg:prime-ts-assets/accounts/avatars/107/780/257/626/128/497/original/454286ac07a6f6e6.jpeg",
"avatar_static": "https://static-assets-1.truthsocial.com/tmtg:prime-ts-assets/accounts/avatars/107/780/257/626/128/497/original/454286ac07a6f6e6.jpeg",
"header": "https://static-assets-1.truthsocial.com/tmtg:prime-ts-assets/accounts/headers/107/780/257/626/128/497/original/ba3b910ba387bf4e.jpeg",
"header_static": "https://static-assets-1.truthsocial.com/tmtg:prime-ts-assets/accounts/headers/107/780/257/626/128/497/original/ba3b910ba387bf4e.jpeg",
"followers_count": 9528704,
"following_count": 72,
"statuses_count": 26249,
"last_status_at": "2025-04-10",
"verified": true,
"location": "",
"website": "www.DonaldJTrump.com",
"unauth_visibility": true,
"chats_onboarded": true,
"feeds_onboarded": true,
"accepting_messages": false,
"show_nonmember_group_statuses": null,
"emojis": [],
"fields": [],
"tv_onboarded": false,
"tv_account": false
},
"media_attachments": [],
"mentions": [],
"tags": [],
"card": null,
"group": null,
"quote": null,
"in_reply_to": null,
"reblog": null,
"sponsored": false,
"replies_count": 797,
"reblogs_count": 2423,
"favourites_count": 8552,
"favourited": false,
"reblogged": false,
"muted": false,
"pinned": false,
"bookmarked": false,
"poll": null,
"emojis": []
}
Check that your response includes the expected fields:
success
(boolean)text
(string)id
(string)created_at
(string)in_reply_to_id
(object)Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.
Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.
Never expose your API key in client-side code. Use environment variables and secure key management practices.
When scraping multiple posts, consider batching requests to maximize throughput while staying within rate limits.
Use asynchronous processing in Kotlin to handle multiple requests concurrently and improve overall performance.
Analyze Truth Social posts to understand market trends, competitor analysis, and audience insights.
Track performance metrics, engagement rates, and content trends across Truth Social posts.
Identify potential customers and business opportunities throughTruth Social data analysis.
Check your API key is correct and properly formatted in the x-api-key header.
You ran out of credits and need to buy more.
The resource might not exist or be private.
Temporary server issue. Implement retry logic with exponential backoff.
ScrapeCreators offers 100 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.
Scraping publicly available data is fair game, and we only collect public data. So anything that you can see in an incognito browser is what we collect.
There is no rate limit! So you can scrape as fast as you want!
All API responses are returned in JSON format, making it easy to integrate with any programming language or application.
Yes! This tutorial focuses on core Kotlin HTTP concepts that work with any framework. The API calls remain the same regardless of your specific Kotlin setup.
For large datasets, implement pagination, use streaming responses where available, and consider storing data in a database for efficient querying.
Get started with 100 free API calls. No credit card required.