# Twitter Profile Scraper (`epctex/twitter-profile-scraper`) Actor

Scrape any Twitter profile of any user. Extract tweets, replies, favorites, retweets, conversation threads and many more without any limit. Gather user related information such as verification, location, profile image, friends, followers, following and much more! No limits on Twitter!

- **URL**: https://apify.com/epctex/twitter-profile-scraper.md
- **Developed by:** [epctex](https://apify.com/epctex) (community)
- **Categories:** Social media
- **Stats:** 3,665 total users, 14 monthly users, 16.5% runs succeeded, 64 bookmarks
- **User rating**: 4.22 out of 5 stars

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Actor - Twitter Profile Scraper

Since Twitter doesn't provide a good and free API, this actor should help you to retrieve data from it.

### Features

- Scrape user detail - Scrape any user-related information from any profile such as friends, followers, following, verified account, location, profile image, profile banner, profile URL, date of creation, and so on.

- Scrape tweet - You can retrieve all the tweets from any profile with all the details. Language, sensitive language, reply, quote, retweet, pinned, retweeted, and all sorts of Tweet-related information.

- Scrape statistics - Gather all the statistical information of a tweet.

- **Authentication Support**: Use Twitter authentication tokens to fetch profile timelines reliably.

### Why use this actor?

This actor is extremely fast and optimized. It'll scrape Twitter profiles around 26 times faster than the other equivalent scrapers. Therefore you will consume fewer resources and it will be cheaper to use it.

### Bugs, fixes, updates, and changelog

This scraper is under active development. If you have any feature requests you can create an issue from [here](https://github.com/epctex-support/twitter-profile-scraper/issues).

### Input Parameters

The input of this scraper should be JSON containing the list of pages on the Twitter Profile Scraper that should be visited. Possible fields are:

- `startUrls`: (Optional) (Array) List of Twitter Profile URLs. You should only provide profile URLs.

- `authTokens`: (Array) Authentication tokens for Twitter (X) to fetch user timelines. **Required when scraping tweets** unless `onlyUserInfo` is enabled.

- `maxTweetsPerUser`: (Optional) (Number) Maximum number of tweets to scrape per profile.

- `addUserInfo`: (Optional) (Boolean) This will add user information into all scraped tweets. Please keep in mind that the size of the output will increase proportionally to the user information.

- `addNotFoundUsersToOutput`: (Optional) (Boolean) Appends an object to the output where the users are not found. It will work only the 'Only User Info' option is enabled.

- `addSuspendedUsersToOutput`: (Optional) (Boolean) Appends an object to the output where the users are suspended. It will work only the 'Only User Info' option is enabled.

- `onlyUserInfo`: (Optional) (Boolean)This option enables you to retrieve only user information and not the tweets of that user.

- `customMapFunction`: (Optional) (String) Function that takes each object's handle as an argument and returns the object with executing the function.

- `proxy`: (Required) (Proxy Object) Proxy configuration.

This solution requires the use of **Proxy servers**, either your own proxy servers or you can use [Apify Proxy](https://www.apify.com/docs/proxy).

#### Tip

**Important**: You must provide your own Twitter/X authentication tokens in the `authTokens` array when scraping tweets. These can be obtained from your Twitter accounts. If you only need profile information, enable `onlyUserInfo` and `authTokens` are not required.

When you want to scrape over a specific profile URL, just copy and paste the link as one of the **startUrl**.

#### Compute Unit Consumption

The actor is optimized to run blazing fast and scrape many tweets as possible. Therefore, it forefronts all tweet detail requests. If the actor doesn't block very often it'll scrape 100 tweets in 20 seconds with ~0.02-0.025 compute units.

#### Twitter Profile Scraper Input example

```json
{
  "proxy":{
    "useApifyProxy":true
  },
  "authTokens": [
    "auth_token_example_1",
    "auth_token_example_2"
  ],
  "addUserInfo":true,
  "maxTweetsPerUser": 100,
  "startUrls":[
    "https://twitter.com/apify"
  ]
}
```

### During the Run

During the run, the actor will output messages letting you know what is going on. Each message always contains a short label specifying which page from the provided list is currently specified.
When items are loaded from the page, you should see a message about this event with a loaded item count and total item count for each page.

If you provide incorrect input to the actor, it will immediately stop with a failure state and output an explanation of what is wrong.

### Twitter Profile Scraper Export

During the run, the actor stores results into a dataset. Each item is a separate item in the dataset.

You can manage the results in any language (Python, PHP, Node JS/NPM). See the FAQ or <a href="https://www.apify.com/docs/api" target="blank">our API reference</a> to learn more about getting results from this Twitter Profile actor.

### Scraped Tweets Properties

The structure of each tweet in Twitter Profile Scraper looks like this:

#### Tweet Detail

```json
{
  "user": {
    "created_at": "Tue Sep 01 08:38:01 +0000 2015",
    "default_profile": false,
    "default_profile_image": false,
    "description": "Apify is a software platform that lets you automate anything a person can do manually in a web browser, and then run it at scale.",
    "entities": {
      "description": {
        "urls": []
      },
      "url": {
        "urls": [
          {
            "display_url": "apify.com",
            "expanded_url": "https://apify.com",
            "url": "https://t.co/TmTF9tTQJv",
            "indices": [
              0,
              23
            ]
          }
        ]
      }
    },
    "fast_followers_count": 0,
    "favourites_count": 347,
    "followers_count": 1032,
    "friends_count": 164,
    "has_custom_timelines": false,
    "is_translator": false,
    "listed_count": 39,
    "location": "The Interweb",
    "media_count": 216,
    "name": "Apify",
    "normal_followers_count": 1032,
    "pinned_tweet_ids_str": [
      "1322257049527472128"
    ],
    "possibly_sensitive": false,
    "profile_banner_extensions": {
      "mediaColor": {
        "r": {
          "ok": {
            "palette": [
              {
                "percentage": 91.13,
                "rgb": {
                  "blue": 255,
                  "green": 249,
                  "red": 242
                }
              },
              {
                "percentage": 5.18,
                "rgb": {
                  "blue": 255,
                  "green": 188,
                  "red": 134
                }
              },
              {
                "percentage": 1.91,
                "rgb": {
                  "blue": 112,
                  "green": 110,
                  "red": 104
                }
              },
              {
                "percentage": 1.78,
                "rgb": {
                  "blue": 255,
                  "green": 157,
                  "red": 87
                }
              }
            ]
          }
        }
      }
    },
    "profile_banner_url": "https://pbs.twimg.com/profile_banners/3510729917/1602246779",
    "profile_image_extensions": {
      "mediaColor": {
        "r": {
          "ok": {
            "palette": [
              {
                "percentage": 86.89,
                "rgb": {
                  "blue": 255,
                  "green": 255,
                  "red": 255
                }
              },
              {
                "percentage": 4.83,
                "rgb": {
                  "blue": 19,
                  "green": 144,
                  "red": 255
                }
              },
              {
                "percentage": 4.27,
                "rgb": {
                  "blue": 1,
                  "green": 215,
                  "red": 150
                }
              },
              {
                "percentage": 3.05,
                "rgb": {
                  "blue": 233,
                  "green": 197,
                  "red": 113
                }
              },
              {
                "percentage": 0.29,
                "rgb": {
                  "blue": 169,
                  "green": 241,
                  "red": 221
                }
              }
            ]
          }
        }
      }
    },
    "profile_image_url_https": "https://pbs.twimg.com/profile_images/1354484488697425920/aQ5dSaTK_normal.jpg",
    "profile_interstitial_type": "",
    "protected": false,
    "screen_name": "apify",
    "statuses_count": 814,
    "translator_type": "none",
    "url": "https://t.co/TmTF9tTQJv",
    "verified": false,
    "withheld_in_countries": []
  },
  "created_at": "Thu Jul 14 13:34:06 +0000 2022",
  "conversation_id_str": "1547575166686793730",
  "display_text_range": [
    0,
    280
  ],
  "entities": {
    "media": [
      {
        "display_url": "pic.twitter.com/n5P2o3E7nG",
        "expanded_url": "https://twitter.com/apify/status/1547575166686793730/photo/1",
        "id_str": "1547575164660879363",
        "indices": [
          281,
          304
        ],
        "media_url_https": "https://pbs.twimg.com/media/FXoXabDUEAMR-4X.jpg",
        "type": "photo",
        "url": "https://t.co/n5P2o3E7nG",
        "features": {
          "large": {
            "faces": [
              {
                "x": 411,
                "y": 60,
                "h": 55,
                "w": 55
              },
              {
                "x": 644,
                "y": 111,
                "h": 57,
                "w": 57
              }
            ]
          },
          "medium": {
            "faces": [
              {
                "x": 411,
                "y": 60,
                "h": 55,
                "w": 55
              },
              {
                "x": 644,
                "y": 111,
                "h": 57,
                "w": 57
              }
            ]
          },
          "small": {
            "faces": [
              {
                "x": 272,
                "y": 39,
                "h": 36,
                "w": 36
              },
              {
                "x": 427,
                "y": 73,
                "h": 37,
                "w": 37
              }
            ]
          },
          "orig": {
            "faces": [
              {
                "x": 411,
                "y": 60,
                "h": 55,
                "w": 55
              },
              {
                "x": 644,
                "y": 111,
                "h": 57,
                "w": 57
              }
            ]
          }
        },
        "sizes": {
          "large": {
            "h": 640,
            "w": 1024,
            "resize": "fit"
          },
          "medium": {
            "h": 640,
            "w": 1024,
            "resize": "fit"
          },
          "small": {
            "h": 425,
            "w": 680,
            "resize": "fit"
          },
          "thumb": {
            "h": 150,
            "w": 150,
            "resize": "crop"
          }
        },
        "original_info": {
          "height": 640,
          "width": 1024,
          "focus_rects": [
            {
              "x": 0,
              "y": 0,
              "w": 1024,
              "h": 573
            },
            {
              "x": 0,
              "y": 0,
              "w": 640,
              "h": 640
            },
            {
              "x": 1,
              "y": 0,
              "w": 561,
              "h": 640
            },
            {
              "x": 121,
              "y": 0,
              "w": 320,
              "h": 640
            },
            {
              "x": 0,
              "y": 0,
              "w": 1024,
              "h": 640
            }
          ]
        }
      }
    ],
    "user_mentions": [],
    "urls": [
      {
        "display_url": "apify.it/3uKtuY5",
        "expanded_url": "https://apify.it/3uKtuY5",
        "url": "https://t.co/3l26ZicZjk",
        "indices": [
          257,
          280
        ]
      }
    ],
    "hashtags": [
      {
        "indices": [
          225,
          242
        ],
        "text": "instagramscraper"
      },
      {
        "indices": [
          243,
          255
        ],
        "text": "webscraping"
      }
    ],
    "symbols": []
  },
  "extended_entities": {
    "media": [
      {
        "display_url": "pic.twitter.com/n5P2o3E7nG",
        "expanded_url": "https://twitter.com/apify/status/1547575166686793730/photo/1",
        "ext_alt_text": "Three iPhone displays showing the description of three Instagram Scrapers from Apify Store: Instagram Profile Scraper, Instagram Hashtag Scraper, and Instagram Comment Scraper.",
        "id_str": "1547575164660879363",
        "indices": [
          281,
          304
        ],
        "media_key": "3_1547575164660879363",
        "media_url_https": "https://pbs.twimg.com/media/FXoXabDUEAMR-4X.jpg",
        "type": "photo",
        "url": "https://t.co/n5P2o3E7nG",
        "ext_media_color": {
          "palette": [
            {
              "percentage": 61.19,
              "rgb": {
                "blue": 242,
                "green": 242,
                "red": 242
              }
            },
            {
              "percentage": 18.76,
              "rgb": {
                "blue": 226,
                "green": 119,
                "red": 211
              }
            },
            {
              "percentage": 9.6,
              "rgb": {
                "blue": 189,
                "green": 120,
                "red": 147
              }
            },
            {
              "percentage": 3.7,
              "rgb": {
                "blue": 63,
                "green": 48,
                "red": 62
              }
            },
            {
              "percentage": 2.01,
              "rgb": {
                "blue": 195,
                "green": 120,
                "red": 228
              }
            }
          ]
        },
        "ext_media_availability": {
          "status": "Available"
        },
        "features": {
          "large": {
            "faces": [
              {
                "x": 411,
                "y": 60,
                "h": 55,
                "w": 55
              },
              {
                "x": 644,
                "y": 111,
                "h": 57,
                "w": 57
              }
            ]
          },
          "medium": {
            "faces": [
              {
                "x": 411,
                "y": 60,
                "h": 55,
                "w": 55
              },
              {
                "x": 644,
                "y": 111,
                "h": 57,
                "w": 57
              }
            ]
          },
          "small": {
            "faces": [
              {
                "x": 272,
                "y": 39,
                "h": 36,
                "w": 36
              },
              {
                "x": 427,
                "y": 73,
                "h": 37,
                "w": 37
              }
            ]
          },
          "orig": {
            "faces": [
              {
                "x": 411,
                "y": 60,
                "h": 55,
                "w": 55
              },
              {
                "x": 644,
                "y": 111,
                "h": 57,
                "w": 57
              }
            ]
          }
        },
        "sizes": {
          "large": {
            "h": 640,
            "w": 1024,
            "resize": "fit"
          },
          "medium": {
            "h": 640,
            "w": 1024,
            "resize": "fit"
          },
          "small": {
            "h": 425,
            "w": 680,
            "resize": "fit"
          },
          "thumb": {
            "h": 150,
            "w": 150,
            "resize": "crop"
          }
        },
        "original_info": {
          "height": 640,
          "width": 1024,
          "focus_rects": [
            {
              "x": 0,
              "y": 0,
              "w": 1024,
              "h": 573
            },
            {
              "x": 0,
              "y": 0,
              "w": 640,
              "h": 640
            },
            {
              "x": 1,
              "y": 0,
              "w": 561,
              "h": 640
            },
            {
              "x": 121,
              "y": 0,
              "w": 320,
              "h": 640
            },
            {
              "x": 0,
              "y": 0,
              "w": 1024,
              "h": 640
            }
          ]
        }
      }
    ]
  },
  "favorite_count": 0,
  "favorited": false,
  "full_text": "Extract profile information from Instagram with Instagram Profile Scraper! 📸 Quick, ready-made, and easy to set up, Instagram Scraper lets you extract usernames, followers &amp; follows, bio, likes, &amp; more. Try it now! 👇 #instagramscraper #webscraping  https://t.co/3l26ZicZjk https://t.co/n5P2o3E7nG",
  "is_quote_status": false,
  "lang": "en",
  "possibly_sensitive": false,
  "possibly_sensitive_editable": true,
  "quote_count": 0,
  "reply_count": 0,
  "retweet_count": 0,
  "retweeted": false,
  "source": "<a href=\"http://www.hubspot.com/\" rel=\"nofollow\">HubSpot</a>",
  "user_id_str": "3510729917",
  "id_str": "1547575166686793730"
}
```

### Contact

Please visit us through [epctex.com](https://epctex.com) to see all the products that are available for you. If you are looking for any custom integration or so, please reach out to us through the chat box in [epctex.com](https://epctex.com). In need of support? <business@epctex.com> is at your service.

# Actor input Schema

## `startUrls` (type: `array`):

URLs to start with. It should be a Twitter Profile url

## `authTokens` (type: `array`):

Twitter auth_token values used to call the UserTweets GraphQL API. Required unless onlyUserInfo is enabled.

## `maxTweetsPerUser` (type: `integer`):

Maximum number of tweets that you want as output per user.

## `onlyUserInfo` (type: `boolean`):

This option enables you to retrieve only user information and not the tweets of that user.

## `addNotFoundUsersToOutput` (type: `boolean`):

Appends an object to the output where the users are not found. It will work only the 'Only User Info' option is enabled.

## `addSuspendedUsersToOutput` (type: `boolean`):

Appends an object to the output where the users are suspended. It will work only the 'Only User Info' option is enabled.

## `addUserInfo` (type: `boolean`):

Appends an object to each tweet containing the user information. You can decrease the size of your dataset by turning this off.

## `customMapFunction` (type: `string`):

Function that takes each of the objects as argument and returns data that will be mapped by the function itself.

## `proxy` (type: `object`):

Select proxies to be used by your crawler.

## Actor input object example

```json
{
  "startUrls": [
    "https://twitter.com/apify"
  ],
  "maxTweetsPerUser": 100,
  "onlyUserInfo": false,
  "addNotFoundUsersToOutput": false,
  "addSuspendedUsersToOutput": false,
  "addUserInfo": true,
  "customMapFunction": "(object) => { return {...object} }",
  "proxy": {
    "useApifyProxy": true
  }
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "startUrls": [
        "https://twitter.com/apify"
    ],
    "maxTweetsPerUser": 100,
    "customMapFunction": (object) => { return {...object} },
    "proxy": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("epctex/twitter-profile-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "startUrls": ["https://twitter.com/apify"],
    "maxTweetsPerUser": 100,
    "customMapFunction": "(object) => { return {...object} }",
    "proxy": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("epctex/twitter-profile-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "startUrls": [
    "https://twitter.com/apify"
  ],
  "maxTweetsPerUser": 100,
  "customMapFunction": "(object) => { return {...object} }",
  "proxy": {
    "useApifyProxy": true
  }
}' |
apify call epctex/twitter-profile-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,epctex/twitter-profile-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/wbpC5fjeAxy06bonV/builds/0ZTNuKKMr1ja65iIE/openapi.json
