Twitter Automation API (POST, REPLY, LIKE, RETWEET, SCRAP))
Pricing
$15.00 / 1,000 results
Twitter Automation API (POST, REPLY, LIKE, RETWEET, SCRAP))
A powerful and flexible Twitter/X automation API built as an Apify Actor. This API enables you to scrape tweets, post new tweets, reply to tweets, like tweets, and retweet using Playwright browser automation.
Pricing
$15.00 / 1,000 results
Rating
5.0
(2)
Developer

Mahmoud Alhamdo
Actor stats
1
Bookmarked
1
Total users
0
Monthly active users
3 days ago
Last modified
Categories
Share
Twitter Automation API
A powerful and flexible Twitter/X automation API built as an Apify Actor. This API enables you to scrape tweets, post new tweets, reply to tweets, like tweets, and retweet using Playwright browser automation.
π Features
-
Multiple Modes:
- User Mode: Scrape latest tweets from any Twitter/X user profile
- Single Tweet Mode: Extract data from a specific tweet URL
- Post Mode: Publish a new tweet
- Reply Mode: Reply to a specific tweet
- Like Mode: Like a single tweet or multiple tweets (up to 5)
- Retweet Mode: Retweet a single tweet or multiple tweets (up to 5)
-
Comprehensive Data Extraction:
- Tweet text content
- Tweet ID and URL
- Author username
- Timestamp
- Engagement metrics (likes, retweets, replies, views, bookmarks)
- Image URLs (if present)
- Image detection flag
-
Smart Features:
- Automatic pinned tweet filtering
- Iterator-based processing (one tweet at a time)
- Real-time data saving to dataset
- Duplicate tweet detection
- Automatic scrolling for pagination
- Batch operations: Like or retweet up to 5 tweets at once
- Configurable delays between actions to avoid rate limiting
-
Robust & Reliable:
- Built with Playwright for JavaScript-heavy sites
- Realistic browser fingerprinting
- Error handling and retry logic
- Configurable scroll delays
π Input Parameters
Required
- mode (string): Operation mode -
"user","single","post","reply","like", or"retweet" - ct0 (string): Twitter ct0 cookie for authentication
- auth_token (string): Twitter auth_token cookie for authentication
For User Mode (Scraping)
- username (string): Twitter username without @ (e.g.,
"AlamawiEth") - maxTweets (integer): Maximum number of tweets to scrape (1-1000, default: 50)
- maxDaysOld (integer): Only scrape tweets from the last N days (0 = no limit, default: 5)
For Single Tweet Mode
- tweetUrl (string): Full URL of the tweet to scrape
For Post Mode (Publish Tweet)
- tweetText (string, required): Text content of the tweet to post
For Reply Mode
- replyTweetUrl (string, required): URL of the tweet to reply to
- replyText (string, required): Text content of the reply
For Like Mode
- tweetUrl (string, optional): URL of a single tweet to like (use this OR tweetUrls)
- tweetUrls (array, optional): Array of tweet URLs to like (maximum 5 tweets). Use this for multiple likes.
- delayBetweenActions (integer, optional): Delay in seconds between processing each tweet when using multiple tweets (0-60, default: 2). Helps avoid rate limiting.
Note: Use either tweetUrl for a single tweet OR tweetUrls for multiple tweets (up to 5).
For Retweet Mode
- tweetUrl (string, optional): URL of a single tweet to retweet (use this OR tweetUrls)
- tweetUrls (array, optional): Array of tweet URLs to retweet (maximum 5 tweets). Use this for multiple retweets.
- delayBetweenActions (integer, optional): Delay in seconds between processing each tweet when using multiple tweets (0-60, default: 2). Helps avoid rate limiting.
Note: Use either tweetUrl for a single tweet OR tweetUrls for multiple tweets (up to 5).
Example Input (User Mode)
{"mode": "user","username": "apify","maxTweets": 50,"maxDaysOld": 5,"ct0": "","auth_token": ""}
Example Input (User Mode with Authentication)
{"mode": "user","username": "apify","maxTweets": 50,"maxDaysOld": 5,"ct0": "your_ct0_cookie_value","auth_token": "your_auth_token_value"}
Example Input (Single Tweet Mode)
{"mode": "single","tweetUrl": "https://x.com/user1/status/1234567890"}
Example Input (Post Tweet Mode)
{"mode": "post","tweetText": "Hello from Apify Actor! π","ct0": "your_ct0_cookie_value","auth_token": "your_auth_token_value"}
Example Input (Reply Mode)
{"mode": "reply","replyTweetUrl": "https://x.com/user1/status/1234567890","replyText": "Great tweet! Thanks for sharing.","ct0": "your_ct0_cookie_value","auth_token": "your_auth_token_value"}
Example Input (Like Mode - Single Tweet)
{"mode": "like","tweetUrl": "https://x.com/user1/status/1234567890","ct0": "your_ct0_cookie_value","auth_token": "your_auth_token_value"}
Example Input (Like Mode - Multiple Tweets)
{"mode": "like","tweetUrls": ["https://x.com/user1/status/1234567890","https://x.com/user2/status/0987654321","https://x.com/user3/status/1122334455"],"delayBetweenActions": 3,"ct0": "your_ct0_cookie_value","auth_token": "your_auth_token_value"}
Example Input (Retweet Mode - Single Tweet)
{"mode": "retweet","tweetUrl": "https://x.com/user1/status/1234567890","ct0": "your_ct0_cookie_value","auth_token": "your_auth_token_value"}
Example Input (Retweet Mode - Multiple Tweets)
{"mode": "retweet","tweetUrls": ["https://x.com/user1/status/1234567890","https://x.com/user2/status/0987654321","https://x.com/user3/status/1122334455"],"delayBetweenActions": 3,"ct0": "your_ct0_cookie_value","auth_token": "your_auth_token_value"}
π Output Schema
For Scraping Modes (user, single)
Each tweet in the dataset contains:
{"tweetId": "1987766870477619331","text": "Tweet text content...","username": "AlamawiEth","timestamp": "2025-11-10T06:18:47.000Z","url": "https://x.com/user1/status/1234567890","likes": 59,"retweets": 4,"replies": 7,"views": 24796,"bookmarks": 0,"images": ["https://pbs.twimg.com/media/XXX?format=jpg&name=medium"],"hasImages": true,"scrapedAt": "2025-11-12T05:00:15.702372"}
For Interaction Modes (post, reply, like, retweet)
Single Tweet Operations:
{"success": true,"tweetId": "1987766870477619331","url": "https://x.com/user1/status/1234567890","text": "Tweet text...","postedAt": "2025-11-12T05:00:15.702372"}
Multiple Tweets Operations (like/retweet):
{"success": true,"tweetUrl": "https://x.com/user1/status/1234567890","tweetIndex": 1,"totalTweets": 3,"action": "liked","likedAt": "2025-11-12T05:00:15.702372"}
Each result includes:
success: Boolean indicating if the operation succeededtweetUrl: URL of the processed tweettweetIndex: Position of this tweet in the batch (1-based)totalTweets: Total number of tweets in the batchaction: Type of action performed (liked,retweeted, etc.)- Timestamp field:
likedAt,retweetedAt,postedAt, orrepliedAt
π Authentication Setup (Optional)
To use advanced search with date filters, you need to provide Twitter authentication cookies (ct0 and auth_token). Here's how to get them using the Cookie Editor Chrome extension:
Step-by-Step Guide:
-
Install Cookie Editor Extension:
- Open Chrome Web Store
- Search for "Cookie Editor" or visit: https://chromewebstore.google.com/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm
- Click "Add to Chrome" to install
-
Login to Twitter/X:
- Open a new tab and go to https://x.com (or https://twitter.com)
- Login to your Twitter/X account normally
-
Open Cookie Editor:
- Click on the Cookie Editor icon in your Chrome toolbar
- Or right-click on the page β "Cookie Editor"
-
Find Required Cookies:
- In the Cookie Editor, search for
ct0 - Copy the Value of the
ct0cookie - Search for
auth_token - Copy the Value of the
auth_tokencookie
- In the Cookie Editor, search for
-
Use in Actor Input:
- Paste the
ct0value in thect0field - Paste the
auth_tokenvalue in theauth_tokenfield
- Paste the
Alternative: Export All Cookies
- In Cookie Editor, click "Export" button
- Select "JSON" format
- Find the cookies in the exported JSON:
{"name": "ct0","value": "your_ct0_value_here"},{"name": "auth_token","value": "your_auth_token_value_here"}
β οΈ Security Warning
- Never share your cookies with anyone you don't trust
- Cookies contain sensitive login information
- Anyone with your cookies can access your account
- Only use cookies in secure environments
- Consider using a separate Twitter account for scraping
Benefits of Using Cookies
- β Access to advanced search with date filters
- β Better filtering of recent tweets
- β More reliable scraping results
- β Can filter tweets by specific date ranges
π How It Works
User Mode Flow
- Check Authentication: If
ct0andauth_tokenare provided:- Uses advanced search URL with date filters (e.g.,
https://x.com/search?q=from:USERNAME since:YYYY-MM-DD) - Twitter filters tweets by date automatically
- More efficient and accurate results
- Uses advanced search URL with date filters (e.g.,
- Otherwise: Uses profile page and filters by date in code
- Navigate to the appropriate URL
- Wait for tweets to load automatically (no manual delays)
- Iterate through tweets one by one:
- Skip pinned tweets automatically
- Filter by date if
maxDaysOldis set - Extract all tweet data
- Save to dataset immediately
- Scroll down to load more tweets (with automatic waiting)
- Continue until reaching
maxTweetsor no more tweets available
Single Tweet Mode Flow
- Navigate to the specific tweet URL
- Wait for tweet to load
- Extract tweet data
- Save to dataset
Post Tweet Mode Flow
- Navigate to Twitter home page
- Wait for compose box to appear
- Enter tweet text
- Click tweet button
- Wait for confirmation
- Return posted tweet data (URL, ID, etc.)
Reply Mode Flow
- Navigate to the tweet URL
- Click reply button
- Enter reply text
- Submit reply
- Return reply confirmation
Like Mode Flow
Single Tweet:
- Navigate to the tweet URL
- Click like button
- Wait for action to complete
- Return like confirmation
Multiple Tweets:
- For each tweet in the
tweetUrlsarray:- Navigate to the tweet URL
- Click like button
- Wait for action to complete
- Return like confirmation with tweet index
- Wait for
delayBetweenActionsseconds before next tweet
- Return results for all processed tweets
Retweet Mode Flow
Single Tweet:
- Navigate to the tweet URL
- Click retweet button
- Confirm retweet (if dialog appears)
- Wait for action to complete
- Return retweet confirmation
Multiple Tweets:
- For each tweet in the
tweetUrlsarray:- Navigate to the tweet URL
- Click retweet button
- Confirm retweet (if dialog appears)
- Wait for action to complete
- Return retweet confirmation with tweet index
- Wait for
delayBetweenActionsseconds before next tweet
- Return results for all processed tweets
π― Use Cases
- Social Media Monitoring: Track tweets from specific accounts
- Content Analysis: Analyze tweet engagement metrics
- Image Collection: Extract images from tweets
- Data Research: Collect tweet data for analysis
- Brand Monitoring: Monitor mentions and engagement
- Automated Posting: Schedule and post tweets automatically
- Engagement Automation: Automatically like, retweet, or reply to tweets (single or batch)
- Social Media Management: Manage Twitter account interactions programmatically
- Batch Operations: Like or retweet multiple tweets efficiently with configurable delays
βοΈ Technical Details
Built With
- Apify SDK - Python SDK for Apify Actors
- Playwright - Browser automation
- Python 3.8+ - Programming language
Architecture
- Iterator-based processing: Processes tweets one at a time for memory efficiency
- Real-time saving: Each tweet is saved immediately after extraction
- Smart filtering: Automatically skips pinned tweets and old tweets (based on
maxDaysOld) - Duplicate detection: Prevents processing the same tweet twice
- Automatic waiting: Uses
wait_for_selectorinstead of fixed delays for better performance - Cookie-based authentication: Supports Twitter cookies for advanced search features
π Privacy & Compliance
- This Actor respects Twitter/X's public data
- Authentication (cookies) is required for interaction modes (post, reply, like, retweet)
- Authentication (cookies) is optional but recommended for scraping modes (user, single)
- Without cookies: Uses profile page, filters by date in code
- With cookies: Uses advanced search, Twitter filters by date automatically
- Private profiles will not be accessible
- Never share your cookies - they contain sensitive login information
- Important: All interaction modes (post, reply, like, retweet) require valid authentication cookies
- Please review Twitter/X Terms of Service before use
- Be mindful of rate limits when using interaction modes
π Resources
- Apify SDK for Python Documentation
- Playwright Python Documentation
- Apify Platform Documentation
- Apify Actors Documentation
π€ Support
π License
This project is part of the Apify Actor template collection. See the Apify platform for licensing details.
π Version History
- v1.0.0: Initial release
- User mode and single tweet mode
- Image extraction
- Pinned tweet filtering
- Iterator-based processing
- Date-based filtering (
maxDaysOld) - Cookie-based authentication support (
ct0,auth_token) - Advanced search URL support with date filters
- Automatic waiting instead of fixed delays
- v1.1.0: Interaction modes added
- Post tweet mode
- Reply to tweet mode
- Like tweet mode
- Retweet mode
- v1.2.0: Batch operations added
- Multiple likes support (up to 5 tweets)
- Multiple retweets support (up to 5 tweets)
- Configurable delay between actions (
delayBetweenActions) - Enhanced error handling for batch operations
- Progress tracking with tweet index and total count
Note: This Actor is designed for educational and research purposes. Always comply with Twitter/X Terms of Service and applicable laws when scraping data.