X.com Twitter API Scraper avatar

X.com Twitter API Scraper

Pricing

from $0.25 / 1,000 each tweet. cheaper for higher plans

Go to Apify Store
X.com Twitter API Scraper

X.com Twitter API Scraper

Scrape Twitter (X) data efficiently with this powerful Apify Actor. Real-time, authentic data. No pre-built databases. Extract tweets, user profiles, and more using keywords, hashtags, URLs, and advanced search filters. Fast, reliable, and cost-effective. #TwitterScraper

Pricing

from $0.25 / 1,000 each tweet. cheaper for higher plans

Rating

3.5

(7)

Developer

xtdata

xtdata

Maintained by Community

Actor stats

50

Bookmarked

3.1K

Total users

72

Monthly active users

41 minutes ago

Last modified

Features

Limited permissions

Share

X.com Twitter API Scraper - Fast and Efficient Tweet Extraction

This Actor provides a powerful and efficient way to scrape data from Twitter (now X). It allows you to extract tweets based on various criteria, making it ideal for researchers, entrepreneurs, data analysts, and anyone needing to gather Twitter data for analysis, and for following new tweets on a schedule.

Key Features

  • Multiple Input Methods: Get the data you need, how you need it:

    • Start URLs: Provide URLs of user profiles, /with_replies, /media, searches, hashtags, or lists (x.com or twitter.com).
    • Search Terms: Use keywords and advanced search operators ( see Advanced Search Guide).
    • Twitter Handles: Extract tweets from specific users.
    • Conversations: Get the replies of tweets by tweet URL, tweet ID, or conversation ID.
  • Powerful Filtering: Refine your results with precise filtering:

    • Maximum Items: Control the number of tweets per query (each URL, search term, handle, or conversation).
    • Sorting: Get results sorted by "Top" or "Latest".
    • Language: Filter by language using ISO 639-1 codes (a full list of supported languages is available in the Actor's input settings).
    • User Verification: Target tweets from verified users or Twitter Blue subscribers.
    • Media Type: Extract only tweets containing images, videos, or quotes.
    • Users, Engagement, and Location: author, inReplyTo, mentioning, minimumFavorites, minimumRetweets, minimumReplies, geotaggedNear with withinRadius, or geocode.
    • Date Range: Specify a start and end date to retrieve tweets within a specific timeframe.
  • Advanced Options:

    • Include Search Terms: Add a field to each tweet showing the search term that matched it.
    • Custom Map Function: Transform the output data using a custom JavaScript function (for data shaping, not filtering).
    • Query Wizard: Easily create complex queries. (Available Tweet X.com Scraper)
  • Lightning-Fast Performance:

    • Scrape tweets with incredible speed. (Tweet X.com Scraper: advertised as 30-80 tweets per second)
  • Cost-Effective:

    • Competitive pricing. Tweet X.com Scraper: $0.50 per 1,000 tweets.

**Tutorial from development team: Tutorial: Scrape Twitter Data with Apify's Tweet X.com Scraper **

Use Cases

  • Market Research: Analyze trends, sentiment, and brand perception.
  • Academic Research: Gather data for social media studies, political science research, and more.
  • Competitive Analysis: Track competitors' activities and public engagement.
  • Data Journalism: Uncover insights and patterns within Twitter data.
  • Historical Data Analysis: Explore past tweets for specific events or periods.

Quick Start Examples

Here are some example input configurations to get you started quickly:

1. Fetching Tweets from a Specific Profile (e.g., NASA) over Several Time Periods:

This example fetches English tweets from the NASA profile (@NASA) in multiple date ranges, sorted by latest.

{
"includeSearchTerms": false,
"onlyImage": false,
"onlyQuote": false,
"onlyTwitterBlue": false,
"onlyVerifiedUsers": false,
"onlyVideo": false,
"searchTerms": [
"from:elonmusk AI since:2023-01-01 until:2023-03-01",
"from:elonmusk AI since:2023-03-01 until:2023-05-01",
"from:elonmusk AI since:2023-05-01 until:2023-07-01",
"from:elonmusk AI since:2023-07-01 until:2023-09-01",
"from:elonmusk AI since:2023-09-01 until:2023-12-01"
],
"sort": "Top",
"tweetLanguage": "en"
}

2. Fetching Replies to a Specific Tweet with a Hashtag:

This example retrieves replies (in English, sorted by top) to a specific tweet (replace tweet_id_here with the actual tweet ID) that include a specific hashtag (replace hashtag_here).

{
"includeSearchTerms": false,
"onlyImage": false,
"onlyQuote": false,
"onlyTwitterBlue": false,
"onlyVerifiedUsers": false,
"onlyVideo": false,
"searchTerms": [
"conversation_id:tweet_id_here #hashtag_here"
],
"sort": "Latest",
"tweetLanguage": "en"
}

Explanation of Key Input Fields:

  • searchTerms: This is the core of your query. You can use advanced search operators (as shown in the NASA example) or a conversation ID combined with a hashtag. Refer to the Advanced Search Guide for all the possibilities.
  • sort: Choose "Latest" for chronological order or "Top" for the most relevant tweets.
  • tweetLanguage: Specify the language code (e.g., "en" for English).
  • only... (e.g., onlyImage, onlyVerifiedUsers): Boolean flags (true/false) to filter for specific tweet characteristics.
  • includeSearchTerms: Set to true if you want an extra field in the output showing which search term matched each tweet.

Getting Replies

A tweet URL or tweet ID needs scrapeReplies, which returns the tweets of its conversation, newest first. Without it the tweet is skipped with a warning. Use the first tweet of the conversation, because replies belong to the conversation of the first tweet. Write IDs as strings.

{
"tweetIds": ["1630332507265589248"],
"scrapeReplies": true,
"maxItems": 100
}

conversationIds does the same without scrapeReplies.

Monitoring New Tweets

Set onlyNewTweets and schedule the Actor. The first run returns tweets as usual and remembers them in a key-value store named x-twitter-monitor-state in your account. Later runs return only tweets that were not returned before. Searches use Latest order in this mode.

{
"searchTerms": ["from:NASA"],
"onlyNewTweets": true,
"monitorKey": "nasa",
"maxItems": 200
}
  • If the memory cannot be read, the run stops without returning or charging tweets.
  • Up to 10,000 of the newest tweets are remembered per query.
  • Use a different monitorKey for each schedule. Avoid running the same monitor twice at the same time.

Pricing

You pay for the events shown in the Pricing section of the Actor, and nothing else. There is no minimum charge per run.

  • start: once per run.
  • result-item: for each tweet saved to the dataset. Duplicates within a query are not saved or charged.
  • query (if shown in pricing): once for each query that successfully returned at least one page, even an empty one.

The Actor stops before it goes over the maximum cost or the maximum charged results you set. Results are not charged when the data cannot be loaded.

Good to Know

  • maxItems is per query. With sort set to Both, it applies to Top and Latest separately, and tweets found by both are returned once.
  • Filters and dates apply to searchTerms. An operator already written in a search term takes priority.
  • If a run is moved to another server, it continues where it stopped.
  • If some queries fail, the others are still returned and a warning is logged. If all fail, the run fails.
  • Respect Twitter's Terms of Service: Always use this tool ethically and responsibly.

Ethical Use and Data Practices

Our 'actor' operates without logging in to X.com. This means it does not implicitly accept any Terms of Service (ToS) that require a login, as we only process data that is publicly displayed and accessible to everyone without authentication.

We are fully committed to the principle of privacy by design and by default. All data collected explicitly excludes sensitive personal information or non-public data.

Furthermore, our actor runs on Apify, an EU-based company, which means our operations are designed to be compliant with relevant EU data protection regulations, including GDPR, where applicable. You can find more information about the legality of web scraping on Apify's blog: https://blog.apify.com/is-web-scraping-legal/

We have implemented robust technical measures to ensure the actor operates gently and does not impose an undue burden on X.com's servers. Our sole purpose is to facilitate responsible research and public data analysis, and we strictly prohibit any use that could cause harm to any party or the platform itself.

Custom Map Function

customMapFunction is plain, synchronous JavaScript that runs in a separate process. It receives a copy of each item and returns the object to save. If it returns nothing, an array or a promise, throws, or takes too long, the original item is saved.

  • Available: all JavaScript built-ins (JSON, Math, Date, RegExp, Intl, Map and so on) and simple versions of console (prints nothing), URL (absolute URLs, read only), structuredClone (JSON values), atob, btoa, crypto.randomUUID() and performance.now().
  • Not available: process, require, the word import, fetch, timers, Buffer, TextEncoder, TextDecoder, URLSearchParams, eval and new Function.

Output Fields

Items keep the original tweet fields, with these additions:

FieldDescription
viewCountNumber of views, or null when not available
full_text_extendedFull text of long posts. full_text is unchanged
author.is_blue_verifiedWhether the author is a Premium (Blue) subscriber
quoteThe quoted tweet, with its own author

Output Example

[
{
"id": "1630332507265589248",
"url": "https://x.com/NASA/status/1630332507265589248",
"twitterUrl": "https://twitter.com/NASA/status/1630332507265589248",
"full_text": "@yalhunzai We have internships open to international students from countries with whom we have agreements: https://t.co/Kl2Lz4qjpw",
"favorite_count": 14,
"retweet_count": 9,
"reply_count": 0,
"quote_count": 0,
"bookmark_count": 1,
"viewCount": 1520,
"author": {
"id_str": "11348282",
"screen_name": "NASA",
"name": "NASA",
"advertiser_account_service_levels": [
"dso",
"media_studio"
],
"advertiser_account_type": "promotable_user",
"analytics_type": "enabled",
"can_dm": false,
"can_media_tag": true,
"created_at": "Wed Dec 19 20:20:32 +0000 2007",
"description": "There's space for everybody. ✨\n\nVerification: https://t.co/8nok3NP4PW",
"entities": {
"description": {
"hashtags": [],
"symbols": [],
"urls": [
{
"display_url": "nasa.gov/socialmedia",
"expanded_url": "http://nasa.gov/socialmedia",
"indices": [
46,
69
],
"url": "https://t.co/8nok3NP4PW"
}
],
"user_mentions": []
},
"url": {
"urls": [
{
"display_url": "nasa.gov",
"expanded_url": "http://www.nasa.gov/",
"indices": [
0,
23
],
"url": "https://t.co/9NkQJKAnuU"
}
]
}
},
"fast_followers_count": 0,
"favourites_count": 16401,
"followers_count": 85752559,
"friends_count": 170,
"geo_enabled": false,
"has_custom_timelines": true,
"has_extended_profile": true,
"is_translator": false,
"location": "Pale Blue Dot",
"media_count": 27374,
"normal_followers_count": 85752559,
"pinned_tweet_ids_str": [],
"profile_background_color": "000000",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/11348282/1718393721",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/1321163587679784960/0ZxKlEKB_normal.jpg",
"profile_interstitial_type": "",
"profile_link_color": "205BA7",
"protected": false,
"statuses_count": 72761,
"translator_type_enum": "Regular",
"url": "https://t.co/9NkQJKAnuU",
"verified": false,
"verified_type": "Government",
"withheld_in_countries": []
},
"bookmarked": false,
"conversation_id_str": "1630332507265589248",
"created_at": "Tue Feb 28 20:28:53 +0000 2023",
"display_text_range": [
11,
130
],
"entities": {
"hashtags": [],
"symbols": [],
"timestamps": [],
"urls": [
{
"display_url": "go.nasa.gov/3EKfKkN",
"expanded_url": "https://go.nasa.gov/3EKfKkN",
"indices": [
107,
130
],
"url": "https://t.co/Kl2Lz4qjpw"
}
],
"user_mentions": [
{
"id_str": "1583456964453040129",
"indices": [
0,
10
],
"name": "Baki bùlen",
"screen_name": "yalhunzai"
}
]
},
"favorited": false,
"in_reply_to_screen_name": "yalhunzai",
"in_reply_to_status_id_str": "1630616311226048513",
"in_reply_to_user_id_str": "1583456964453040129",
"is_quote_status": false,
"lang": "en",
"possibly_sensitive": false,
"possibly_sensitive_editable": true,
"retweeted": false,
"user_id_str": "11348282"
}
]

Troubleshooting

If you encounter issues like too few results, no results, or incomplete tweet collection, refer to the detailed troubleshooting section in the Actor's input schema or documentation. Common causes include overly restrictive filters or exceeding rate limits.

Get Started

Start scraping Twitter data today! This Actor provides a powerful, flexible, and cost-effective solution for all your Twitter data extraction needs.

🎹️ Fast TikTok API📹️ TikTok Trend API🔍️ TikTok Search API
🧛️ TikTok User API🧛️ TikTok User Info API#️ TikTok Hashtag API
🛍️ TikTok Shop API👤️ TikTok Followers API⚡️ TikTok Scraper (pay-per-result)
💬 TikTok Comment API🎶 TikTok Music API🎶 TikTok Music Trend API
🎶 Tiktok Scraper Ultimate (pay-per-event)