How to Scrape Twitter Tweet Details
Get detailed information about a specific tweet. This guide walks you through the entire process, with copy-paste code examples in Node.js, JavaScript, Python, PHP, Ruby, Java, C#, Go, Rust, TypeScript, Swift, Kotlin, R and cURL.
Overview
What You'll Learn
- Setting up your environment
- Installing the required HTTP client
- Authenticating with SociaVault API
- Making requests to Twitter
- Handling responses and errors
What You'll Get
- Access to tweet data
- JSON formatted responses
- Real-time data access
- Scalable solution
- Error handling patterns
Prerequisites
1. API Key
First, you'll need a SociaVault API key to authenticate your requests.
2. Development Environment
Make sure you have the following ready:
- Your preferred language installed (Python, Node.js, etc.)
- A code editor (VS Code, Sublime, etc.)
- Command line interface access
Implementation
Pick your language below — the install command and full code example update accordingly.
Step 1: Install the HTTP client (Node.js)
We'll use axios to make HTTP requests in Node.js.
npm install axiosStep 2: Make the request (Node.js)
Here's the full Node.js example. Replace YOUR_API_KEY with your actual API key.
import axios from 'axios';
const API_KEY = 'YOUR_API_KEY';
async function scrape() {
try {
const response = await axios.get(`https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890`, {
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
});
console.log('Response:', response.data);
return response.data;
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
// Usage
scrape();Step 1: Install the HTTP client (JavaScript)
We'll use fetch to make HTTP requests in JavaScript.
# Native fetch APIStep 2: Make the request (JavaScript)
Here's the full JavaScript example. Replace YOUR_API_KEY with your actual API key.
const API_KEY = 'YOUR_API_KEY';
async function scrape() {
try {
const response = await fetch(`https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890`, {
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log('Response:', data);
return data;
} catch (error) {
console.error('Error:', error);
}
}
scrape();Step 1: Install the HTTP client (Python)
We'll use requests to make HTTP requests in Python.
pip install requestsStep 2: Make the request (Python)
Here's the full Python example. Replace YOUR_API_KEY with your actual API key.
import requests
api_key = "YOUR_API_KEY"
url = "https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890"
headers = {
"x-api-key": api_key,
"Content-Type": "application/json"
}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
print("Response:", data)
except requests.exceptions.RequestException as e:
print("Error:", e)Step 1: Install the HTTP client (PHP)
We'll use curl to make HTTP requests in PHP.
# PHP cURL extension requiredStep 2: Make the request (PHP)
Here's the full PHP example. Replace YOUR_API_KEY with your actual API key.
<?php
$apiKey = "YOUR_API_KEY";
$url = "https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"x-api-key: $apiKey",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>Step 1: Install the HTTP client (Ruby)
We'll use net/http to make HTTP requests in Ruby.
# Standard libraryStep 2: Make the request (Ruby)
Here's the full Ruby example. Replace YOUR_API_KEY with your actual API key.
require 'net/http'
require 'json'
url = URI("https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = "YOUR_API_KEY"
request["Content-Type"] = "application/json"
response = http.request(request)
puts response.read_bodyStep 1: Install the HTTP client (Java)
We'll use HttpClient to make HTTP requests in Java.
// Java 11+ Standard LibraryStep 2: Make the request (Java)
Here's the full Java example. Replace YOUR_API_KEY with your actual API key.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Scraper {
public static void main(String[] args) throws Exception {
String apiKey = "YOUR_API_KEY";
String url = "https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-api-key", apiKey)
.header("Content-Type", "application/json")
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}Step 1: Install the HTTP client (C#)
We'll use HttpClient to make HTTP requests in C#.
// .NET Standard LibraryStep 2: Make the request (C#)
Here's the full C# example. Replace YOUR_API_KEY with your actual API key.
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program {
static async Task Main() {
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");
var response = await client.GetAsync("https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}Step 1: Install the HTTP client (Go)
We'll use net/http to make HTTP requests in Go.
// Standard libraryStep 2: Make the request (Go)
Here's the full Go example. Replace YOUR_API_KEY with your actual API key.
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "YOUR_API_KEY")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}Step 1: Install the HTTP client (Rust)
We'll use reqwest to make HTTP requests in Rust.
cargo add reqwest tokioStep 2: Make the request (Rust)
Here's the full Rust example. Replace YOUR_API_KEY with your actual API key.
use reqwest;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let resp = client.get("https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890")
.header("x-api-key", "YOUR_API_KEY")
.header("Content-Type", "application/json")
.send()
.await?
.text()
.await?;
println!("{}", resp);
Ok(())
}Step 1: Install the HTTP client (TypeScript)
We'll use axios to make HTTP requests in TypeScript.
npm install axiosStep 2: Make the request (TypeScript)
Here's the full TypeScript example. Replace YOUR_API_KEY with your actual API key.
import axios from 'axios';
const API_KEY: string = 'YOUR_API_KEY';
interface ResponseData {
[key: string]: any;
}
async function scrape(): Promise<ResponseData | void> {
try {
const response = await axios.get<ResponseData>(`https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890`, {
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
});
console.log('Response:', response.data);
return response.data;
} catch (error) {
console.error('Error:', error);
}
}
scrape();Step 1: Install the HTTP client (Swift)
We'll use URLSession to make HTTP requests in Swift.
// Standard libraryStep 2: Make the request (Swift)
Here's the full Swift example. Replace YOUR_API_KEY with your actual API key.
import Foundation
let url = URL(string: "https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.addValue("YOUR_API_KEY", forHTTPHeaderField: "x-api-key")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
if let json = try? JSONSerialization.jsonObject(with: data, options: []) {
print(json)
}
}
}
task.resume()Step 1: Install the HTTP client (Kotlin)
We'll use OkHttp to make HTTP requests in Kotlin.
implementation("com.squareup.okhttp3:okhttp:4.10.0")Step 2: Make the request (Kotlin)
Here's the full Kotlin example. Replace YOUR_API_KEY with your actual API key.
import okhttp3.OkHttpClient
import okhttp3.Request
fun main() {
val client = OkHttpClient()
val request = Request.Builder()
.url("https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890")
.addHeader("x-api-key", "YOUR_API_KEY")
.addHeader("Content-Type", "application/json")
.build()
client.newCall(request).execute().use { response ->
println(response.body?.string())
}
}Step 1: Install the HTTP client (R)
We'll use httr to make HTTP requests in R.
install.packages('httr')Step 2: Make the request (R)
Here's the full R example. Replace YOUR_API_KEY with your actual API key.
library(httr)
url <- "https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890"
response <- GET(url, add_headers("x-api-key" = "YOUR_API_KEY", "Content-Type" = "application/json"))
content(response, "text")Step 1: Install the HTTP client (cURL)
We'll use curl to make HTTP requests in cURL.
# No installation required on most systemsStep 2: Make the request (cURL)
Here's the full cURL example. Replace YOUR_API_KEY with your actual API key.
curl -X GET "https://api.sociavault.com/twitter/tweet?url=https%3A%2F%2Fx.com%2Fuser%2Fstatus%2F1234567890" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json"Testing Your Code
API Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| url | string | Yes | Example: https://x.com/user/status/1234567890 |
Expected Response
You should receive a structured JSON response containing the tweet data.
{
"__typename": "Tweet",
"rest_id": "1628769691547074562",
"core": {
"user_results": {
"result": {
"__typename": "User",
"id": "VXNlcjo0NTIwMjQxMjA5",
"rest_id": "4520241209",
"is_blue_verified": true,
"profile_image_shape": "Circle",
"legacy": {
"created_at": "Fri Dec 18 02:48:59 +0000 2015",
"default_profile": false,
"default_profile_image": false,
"description": "Social Media Scraping API's: https://t.co/eSvJcfOZwF\n\nWeb Scraping Course: https://t.co/Sh9N0rAxXk",
"entities": {
"description": {
"urls": [
{
"display_url": "sociavault.com",
"expanded_url": "https://sociavault.com/",
"url": "https://t.co/eSvJcfOZwF",
"indices": [
29
]
}
]
},
"url": {
"urls": [
{
"display_url": "thewebscrapingguy.com",
"expanded_url": "https://thewebscrapingguy.com/",
"url": "https://t.co/gNUelkV9LA",
"indices": [
0
]
}
]
}
},
"fast_followers_count": 0,
"favourites_count": 85211,
"followers_count": 16488,
"friends_count": 1129,
"has_custom_timelines": true,
"is_translator": false,
"listed_count": 151,
"location": "Austin, TX",
"media_count": 1133,
"name": "Adrian | The Web Scraping Guy",
"normal_followers_count": 16488,
"pinned_tweet_ids_str": [
"1628769691547074562"
],
"possibly_sensitive": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/4520241209/1710267319",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/1413647704161275904/1tTdl4v9_normal.jpg",
"profile_interstitial_type": "",
"screen_name": "adrian_horning_",
"statuses_count": 17305,
"translator_type": "none",
"url": "https://t.co/gNUelkV9LA",
"verified": false
},
"professional": {
"rest_id": "1554172330263339015",
"professional_type": "Business"
},
"tipjar_settings": {
"is_enabled": false,
"bandcamp_handle": "",
"bitcoin_handle": "",
"cash_app_handle": "",
"ethereum_handle": "",
"gofundme_handle": "",
"patreon_handle": "",
"pay_pal_handle": "",
"venmo_handle": ""
}
}
}
},
"edit_control": {
"edit_tweet_ids": [
"1628769691547074562"
],
"editable_until_msecs": "1677165730000",
"is_edit_eligible": false,
"edits_remaining": "5"
},
"is_translatable": false,
"views": {
"count": "101132",
"state": "EnabledWithCount"
},
"source": "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Twitter Web App</a>",
"legacy": {
"bookmark_count": 1159,
"bookmarked": false,
"created_at": "Thu Feb 23 14:52:10 +0000 2023",
"conversation_id_str": "1628769691547074562",
"display_text_range": [
0
],
"entities": {
"urls": [
{
"display_url": "lemondrops.io",
"expanded_url": "http://lemondrops.io",
"url": "https://t.co/Fv4phrfgen",
"indices": [
74
]
}
]
},
"favorite_count": 402,
"favorited": false,
"full_text": "I’ve scraped huge retailers, real estate sites, county websites, and sold https://t.co/Fv4phrfgen, which scraped lululemon. \n\nAnd here is EVERYTHING I know about web scraping 👇",
"is_quote_status": false,
"lang": "en",
"possibly_sensitive": false,
"possibly_sensitive_editable": true,
"quote_count": 7,
"reply_count": 41,
"retweet_count": 30,
"retweeted": false,
"user_id_str": "4520241209",
"id_str": "1628769691547074562"
}
}Best Practices
Error Handling
Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.
Caching
Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.
Security
Never expose your API key in client-side code. Use environment variables and secure key management practices.
Troubleshooting
Unauthorized
Check your API key is correct and properly formatted in the x-api-key header.
Payment Required
You ran out of credits and need to buy more.
Not Found
The resource (user, video, etc.) might not exist or be private.
Too Many Requests
You have exceeded your rate limit. Slow down your requests.
Frequently Asked Questions
How much does it cost to scrape Twitter?
SociaVault offers 50 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.
Is it legal to scrape Twitter data?
Scraping publicly available data is generally considered legal. We only collect public data that is accessible without logging in.
Which programming languages can I use to scrape Twitter?
Any language that can make an HTTP request. This tutorial includes ready-to-use examples in Node.js, JavaScript, Python, PHP, Ruby, Java, C#, Go, Rust, TypeScript, Swift, Kotlin, R, cURL.
What data format does the API return?
All API responses are returned in JSON format, making it easy to integrate with any programming language or application.
Related Tutorials
Ready to Start Scraping?
Get started with 50 free API calls. No credit card required. Stop worrying about proxies and captchas.