Twitter Automation API (POST, REPLY, LIKE,  RETWEET, SCRAP))

Twitter Automation API (POST, REPLY, LIKE, RETWEET, SCRAP))

by hamdo

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, lik...

492 runs
6 users
Try This Actor

Opens on Apify.com

About 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.

What does this actor do?

Twitter Automation API (POST, REPLY, LIKE, RETWEET, SCRAP)) is a web scraping and automation tool available on the Apify platform. It's designed to help you extract data and automate tasks efficiently in the cloud.

Key Features

  • Cloud-based execution - no local setup required
  • Scalable infrastructure for large-scale operations
  • API access for integration with your applications
  • Built-in proxy rotation and anti-blocking measures
  • Scheduled runs and webhooks for automation

How to Use

  1. Click "Try This Actor" to open it on Apify
  2. Create a free Apify account if you don't have one
  3. Configure the input parameters as needed
  4. Run the actor and download your results

Documentation

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) json { "mode": "user", "username": "apify", "maxTweets": 50, "maxDaysOld": 5, "ct0": "", "auth_token": "" } ### Example Input (User Mode with Authentication) json { "mode": "user", "username": "apify", "maxTweets": 50, "maxDaysOld": 5, "ct0": "your_ct0_cookie_value", "auth_token": "your_auth_token_value" } ### Example Input (Single Tweet Mode) json { "mode": "single", "tweetUrl": "https://x.com/user1/status/1234567890" } ### Example Input (Post Tweet Mode) json { "mode": "post", "tweetText": "Hello from Apify Actor! 🚀", "ct0": "your_ct0_cookie_value", "auth_token": "your_auth_token_value" } ### Example Input (Reply Mode) json { "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) json { "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) json { "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) json { "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) json { "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: json { "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: json { "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): json { "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 succeeded - tweetUrl: URL of the processed tweet - tweetIndex: Position of this tweet in the batch (1-based) - totalTweets: Total number of tweets in the batch - action: Type of action performed (liked, retweeted, etc.) - Timestamp field: likedAt, retweetedAt, postedAt, or repliedAt ## 🔐 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: 1. 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 2. 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 3. Open Cookie Editor: - Click on the Cookie Editor icon in your Chrome toolbar - Or right-click on the page → "Cookie Editor" 4. Find Required Cookies: - In the Cookie Editor, search for ct0 - Copy the Value of the ct0 cookie - Search for auth_token - Copy the Value of the auth_token cookie 5. Use in Actor Input: - Paste the ct0 value in the ct0 field - Paste the auth_token value in the auth_token field ### Alternative: Export All Cookies 1. In Cookie Editor, click "Export" button 2. Select "JSON" format 3. Find the cookies in the exported JSON: 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 1. Check Authentication: If ct0 and auth_token are 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 2. Otherwise: Uses profile page and filters by date in code 3. Navigate to the appropriate URL 4. Wait for tweets to load automatically (no manual delays) 5. Iterate through tweets one by one: - Skip pinned tweets automatically - Filter by date if maxDaysOld is set - Extract all tweet data - Save to dataset immediately 6. Scroll down to load more tweets (with automatic waiting) 7. Continue until reaching maxTweets or no more tweets available ### Single Tweet Mode Flow 1. Navigate to the specific tweet URL 2. Wait for tweet to load 3. Extract tweet data 4. Save to dataset ### Post Tweet Mode Flow 1. Navigate to Twitter home page 2. Wait for compose box to appear 3. Enter tweet text 4. Click tweet button 5. Wait for confirmation 6. Return posted tweet data (URL, ID, etc.) ### Reply Mode Flow 1. Navigate to the tweet URL 2. Click reply button 3. Enter reply text 4. Submit reply 5. Return reply confirmation ### Like Mode Flow Single Tweet: 1. Navigate to the tweet URL 2. Click like button 3. Wait for action to complete 4. Return like confirmation Multiple Tweets: 1. For each tweet in the tweetUrls array: - Navigate to the tweet URL - Click like button - Wait for action to complete - Return like confirmation with tweet index - Wait for delayBetweenActions seconds before next tweet 2. Return results for all processed tweets ### Retweet Mode Flow Single Tweet: 1. Navigate to the tweet URL 2. Click retweet button 3. Confirm retweet (if dialog appears) 4. Wait for action to complete 5. Return retweet confirmation Multiple Tweets: 1. For each tweet in the tweetUrls array: - 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 delayBetweenActions seconds before next tweet 2. 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_selector instead 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 - Apify Discord Community - Apify Documentation - GitHub Issues ## 📝 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.

Common Use Cases

Market Research

Gather competitive intelligence and market data

Lead Generation

Extract contact information for sales outreach

Price Monitoring

Track competitor pricing and product changes

Content Aggregation

Collect and organize content from multiple sources

Ready to Get Started?

Try Twitter Automation API (POST, REPLY, LIKE, RETWEET, SCRAP)) now on Apify. Free tier available with no credit card required.

Start Free Trial

Actor Information

Developer
hamdo
Pricing
Paid
Total Runs
492
Active Users
6
Apify Platform

Apify provides a cloud platform for web scraping, data extraction, and automation. Build and run web scrapers in the cloud.

Learn more about Apify

Need Professional Help?

Couldn't solve your problem? Hire a verified specialist on Fiverr to get it done quickly and professionally.

Find a Specialist

Trusted by millions | Money-back guarantee | 24/7 Support