Twitter API Documentation
Complete reference for all available endpoints, request formats, and response structures
Quick Navigation
Authentication
API Key Authentication
All Twitter API endpoints require authentication via API key. Include your API key in the request header:
X-API-Key: your-api-key-here
Getting Your API Key
To get your API key:
- Sign up for an account at tweetcore.dev/register
- Choose a pricing plan that fits your needs
- Go to your dashboard to generate API keys
- Copy your API key and include it in all requests
Twitter API Endpoints
Get User Profile
GET/api/twitter/profile/{username}
Retrieve detailed information about a Twitter user profile.
Parameters
Twitter username without @ symbol
Code Examples
// Get user profile const getProfile = async (username) => { try { const response = await fetch(`https://tweetcore.dev/api/twitter/profile/${username}`, { headers: { 'X-API-Key': 'your-api-key-here' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log('User profile:', data); return data; } catch (error) { console.error('Error fetching profile:', error); } }; // Usage getProfile('elonmusk');
Example Response
{ "id": "1234567890", "username": "johndoe", "name": "John Doe", "bio": "Software developer and tech enthusiast", "followers": 1523, "following": 342, "tweets": 5672, "verified": false, "created_at": "2015-03-21T12:00:00Z", "profile_image": "https://pbs.twimg.com/profile_images/...", "banner_image": "https://pbs.twimg.com/profile_banners/..." }
Get User Tweets
GET/api/twitter/user/{username}/tweets
Retrieve recent tweets from a specific user by username.
Parameters
Twitter username without @ symbol
Number of tweets to return (default: 20, max varies by plan)
Pagination cursor for getting more tweets
Code Examples
// Get user tweets const getTweets = async (username, count = 20, cursor = null) => { try { let url = `https://tweetcore.dev/api/twitter/user/${username}/tweets?count=${count}`; if (cursor) url += `&cursor=${cursor}`; const response = await fetch(url, { headers: { 'X-API-Key': 'your-api-key-here' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(`Found ${data.count} tweets`); return data; } catch (error) { console.error('Error fetching tweets:', error); } }; // Usage getTweets('elonmusk', 10);
Example Response
{ "username": "elonmusk", "user_id": "44196397", "tweets": [ { "id": "1623456789012345678", "text": "Just launched my new project! Check it out...", "created_at": "2024-01-15T14:30:00Z", "likes": 42, "retweets": 12, "replies": 5, "media": [], "entities": { "hashtags": ["launch", "project"], "mentions": [], "urls": ["https://example.com"] } } ], "count": 10, "next_cursor": "DAABCgABF__", "has_more": true }
Get Tweet Details
GET/api/twitter/tweet/{tweet_id}
Retrieve detailed information about a specific tweet.
Parameters
Unique identifier of the tweet
Code Examples
// Get tweet details const getTweetDetails = async (tweetId) => { try { const response = await fetch(`https://tweetcore.dev/api/twitter/tweet/${tweetId}`, { headers: { 'X-API-Key': 'your-api-key-here' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log('Tweet details:', data); return data; } catch (error) { console.error('Error fetching tweet:', error); } }; // Usage getTweetDetails('1623456789012345678');
Example Response
{ "id": "1623456789012345678", "text": "Just launched my new project! Check it out...", "created_at": "2024-01-15T14:30:00Z", "author": { "id": "1234567890", "username": "johndoe", "name": "John Doe", "verified": false }, "stats": { "likes": 42, "retweets": 12, "replies": 5, "quotes": 2, "bookmarks": 8 }, "media": [], "thread": { "is_thread": false, "thread_id": null } }
Get Tweet Conversation Details
GET/api/twitter/tweet/{tweet_id}/details
Get full conversation details for a tweet including the main tweet and all replies in chronological order. Uses secure cursor-based pagination for efficient browsing through large conversation threads.
Parameters
Unique identifier of the tweet to get conversation for
Number of tweets to return (default: 20, max varies by plan)
Secure pagination cursor token for getting more tweets in the conversation
Code Examples
// Get tweet conversation with pagination const getConversation = async (tweetId, count = 20, cursor = null) => { try { let url = `https://tweetcore.dev/api/twitter/tweet/${tweetId}/details?count=${count}`; if (cursor) url += `&cursor=${cursor}`; const response = await fetch(url, { headers: { 'X-API-Key': 'your-api-key-here' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(`Found ${data.count} tweets in conversation`); console.log(`Main tweet: ${data.main_tweet?.text}`); console.log(`Total replies: ${data.tweets.length - 1}`); // Check if more pages available if (data.has_more) { console.log(`Next cursor: ${data.next_cursor}`); } return data; } catch (error) { console.error('Error fetching conversation:', error); } }; // Usage - get first page getConversation('1935903191784390903', 5); // Usage - get next page with cursor getConversation('1935903191784390903', 5, 'KEynpesc-bpn9sIxILhlAR_ntipGQYxeJu7eKHt8Jq4');
Example Response
{ "tweet_id": "1935903191784390903", "tweets": [ { "id": "1935903191784390903", "text": "Incredible Japan 🇯🇵🧵 Thread about Japanese innovation...", "created_at": "2024-12-17T06:20:45Z", "author": { "id": "44196397", "username": "elonmusk", "name": "Elon Musk", "verified": true }, "stats": { "likes": 25420, "retweets": 8340, "replies": 1250, "quotes": 892 }, "media": [], "is_main_tweet": true }, { "id": "1935904123456789012", "text": "Amazing thread! Thanks for sharing this perspective on Japan.", "created_at": "2024-12-17T06:25:12Z", "author": { "id": "123456789", "username": "tech_enthusiast", "name": "Tech Enthusiast", "verified": false }, "stats": { "likes": 245, "retweets": 12, "replies": 5, "quotes": 2 }, "media": [], "is_main_tweet": false, "reply_to": "1935903191784390903" } ], "count": 5, "total_found": 1250, "next_cursor": "KEynpesc-bpn9sIxILhlAR_ntipGQYxeJu7eKHt8Jq4", "has_more": true, "main_tweet": { "id": "1935903191784390903", "text": "Incredible Japan 🇯🇵🧵 Thread about Japanese innovation...", "author": { "username": "elonmusk", "name": "Elon Musk" } }, "endpoint_used": "conversation_details" }
🔒 Secure Pagination
This endpoint uses secure cursor-based pagination with randomly generated 43-character tokens stored in the database. Each cursor is tied to your API key and the specific tweet conversation, preventing manipulation and ensuring consistent results. Cursors expire after 24 hours for security.
Search Tweets
GET/api/twitter/search/tweets
Search for tweets matching specified criteria.
Parameters
Search query (supports keywords, hashtags, mentions)
Number of results to return (default: 10, max: 100)
Code Examples
// Search tweets const searchTweets = async (query, limit = 10) => { try { const response = await fetch(`https://tweetcore.dev/api/twitter/search/tweets?q=${encodeURIComponent(query)}&limit=${limit}`, { headers: { 'X-API-Key': 'your-api-key-here' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(`Found ${data.count} tweets for "${query}"`); return data; } catch (error) { console.error('Error searching tweets:', error); } }; // Usage searchTweets('bitcoin', 5);
Example Response
{ "query": "bitcoin", "results": [ { "id": "search_tweet_0", "text": "Tweet containing 'bitcoin' - result #1", "author": { "username": "user_0", "name": "User 0" }, "created_at": "2024-01-01T00:00:00Z", "likes_count": 50, "retweets_count": 25 } ], "count": 10 }
Embed System
About Embed System
The embed system allows you to create public Twitter timeline embeds without exposing your API keys. Perfect for websites, blogs, and applications that need to display Twitter content to end users.
How it works: Generate embed tokens using your API key, then use those tokens in public URLs that don't require authentication.
Create Embed Token
POST/api/twitter/embed/tokens
Generate a secure embed token for public Twitter timeline embedding.
Request Body
{ "domain": "mywebsite.com", // Optional: restrict to domain "username": "elonmusk", // Optional: restrict to user "max_requests_per_day": 1000 // Daily usage limit }
Example Response
{ "embed_token": "ABC123DEF456GHI789JKL012MNO345PQR678STU901VWX234YZ", "domain": "mywebsite.com", "username": "elonmusk", "max_requests_per_day": 1000, "created_at": "2024-01-15T10:00:00Z", "usage_instructions": { "embed_url": "/api/twitter/embed/ABC123.../{username}/tweets", "iframe_example": "<iframe src=\"/api/twitter/embed/ABC123.../elonmusk/tweets?count=10\" width=\"600\" height=\"800\"></iframe>" } }
List Embed Tokens
GET/api/twitter/embed/tokens
List all active embed tokens for your account with usage statistics.
Example Response
{ "embed_tokens": [ { "token": "ABC123DEF456...", // Truncated for security "domain": "mywebsite.com", "username": "elonmusk", "max_requests_per_day": 1000, "usage_count": 245, "last_used": "2024-01-15T14:30:00Z", "created_at": "2024-01-15T10:00:00Z" } ], "total": 1 }
Public Embed Endpoint
GET/api/twitter/embed/{embed_token}/{username}/tweets
Public endpoint that returns HTML Twitter timeline without requiring API key authentication. Perfect for iframe embedding on websites.
Parameters
Your generated embed token
Twitter username without @ symbol
Number of tweets to show (default: 10, max: 20)
Optimize for iframe embedding (default: true)
Usage Examples
Direct URL Access:
https://tweetcore.dev/api/twitter/embed/ABC123.../elonmusk/tweets?count=15
Iframe Embed:
<iframe src="https://tweetcore.dev/api/twitter/embed/ABC123.../elonmusk/tweets?count=10" width="600" height="800" frameborder="0" style="border-radius: 12px;"> </iframe>
Security & Usage Controls
Limit embed tokens to specific domains to prevent unauthorized usage.
Optionally restrict tokens to specific Twitter usernames only.
Set daily request limits per embed token to control usage.
Track embed usage with detailed analytics and referer information.
User Management
Create API Key
POST/api/users/api-keys
Generate a new API key for the authenticated user.
Request Body
{ "name": "Production API Key", "description": "Key for production environment" }
Example Response
{ "id": 1, "key": "sk_live_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6", "name": "Production API Key", "description": "Key for production environment", "created_at": "2024-01-15T10:00:00Z", "last_used": null, "is_active": true }
Get User Statistics
GET/api/users/stats
Get usage statistics for the authenticated user.
Example Response
{ "total_requests": 15234, "monthly_requests": 3421, "request_limit": 10000, "remaining_requests": 6579, "reset_date": "2024-02-01T00:00:00Z", "plan": { "name": "Pro", "price": 29, "rate_limit": 5 } }
Rate Limits
Rate Limit Headers
All API responses include rate limit information in the headers:
X-RateLimit-Limit
Maximum requests per second for your plan
X-RateLimit-Remaining
Remaining requests in current window
X-RateLimit-Reset
Unix timestamp when the rate limit window resets
X-Monthly-Limit
Total monthly request limit for your plan
X-Monthly-Remaining
Remaining monthly requests
Note: Exceeding rate limits will result in a 429 Too Many Requests response. Your requests will be automatically throttled based on your plan's limits.
Error Handling
Error Response Format
All errors follow a consistent format:
{ "error": { "code": "RATE_LIMIT_EXCEEDED", "message": "Too many requests. Please retry after 60 seconds.", "details": { "retry_after": 60, "limit": 5, "window": "1s" } } }
Common Error Codes
Code Examples
Python Example
import requests API_KEY = "your-api-key-here" BASE_URL = "https://tweetcore.dev" headers = { "X-API-Key": API_KEY, "Content-Type": "application/json" } # Get user profile response = requests.get( f"{BASE_URL}/api/twitter/profile/elonmusk", headers=headers ) if response.status_code == 200: profile = response.json() print(f"Followers: {profile['followers']}") else: print(f"Error: {response.status_code}")
JavaScript Example
const API_KEY = 'your-api-key-here'; const BASE_URL = 'https://tweetcore.dev'; async function getUserProfile(username) { try { const response = await fetch( `${BASE_URL}/api/twitter/profile/${username}`, { headers: { 'X-API-Key': API_KEY, 'Content-Type': 'application/json' } } ); if (!response.ok) { throw new Error(`Error: ${response.status}`); } const profile = await response.json(); console.log(`Followers: ${profile.followers}`); } catch (error) { console.error('Failed to fetch profile:', error); } } getUserProfile('elonmusk');
cURL Example
curl -X GET "https://tweetcore.dev/api/twitter/profile/elonmusk" \ -H "X-API-Key: your-api-key-here" \ -H "Content-Type: application/json"
Need Help?
If you have questions or need assistance with the API, we're here to help.