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

Pricing

$15.00 / 1,000 results

Go to Apify Store
Twitter Automation API (POST, REPLY, LIKE,  RETWEET, SCRAP))

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

Mahmoud Alhamdo

Maintained by Community

Actor stats

1

Bookmarked

1

Total users

0

Monthly active users

3 days ago

Last modified

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 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:

  2. Login to Twitter/X:

  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:
    {
    "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

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