# Twitter User By Username (`patient_discovery/twitter-user`) Actor

Get Twitter user by username.

- **URL**: https://apify.com/patient\_discovery/twitter-user.md
- **Developed by:** [Surge Street](https://apify.com/patient_discovery) (community)
- **Categories:** Social media
- **Stats:** 26 total users, 3 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: 4.00 out of 5 stars

## Pricing

from $1.50 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

"# Twitter (X.com) User Extractor (Rich Metadata) cookieless

### Overview

This actor performs a deep extraction of Twitter (X.com) user profile metadata by username, delivering comprehensive account information including verification status, engagement metrics, location data, and security indicators. The extraction operates without cookie dependencies, ensuring reliable data retrieval with high fidelity and structural consistency. All timestamps are returned in ISO 8601 format (UTC), and nested objects maintain strict schema adherence for downstream analytical processing.

### Data Dictionary

| Field Name | Data Type | Definition |
|------------|-----------|------------|
| `user_id` | String | Internal unique identifier assigned to the user profile |
| `username` | String | Twitter handle (without @ symbol) used for account identification |
| `external_id` | String | Platform-native user identifier from Twitter's internal system |
| `scraped_at` | String (ISO 8601) | UTC timestamp indicating when the data extraction occurred |
| `account_created` | String (ISO 8601) | UTC timestamp of the original account creation date |
| `is_verified` | Boolean | Indicates whether the account has official verification status (blue checkmark) |
| `is_active` | Boolean | Indicates whether the account is currently active and not suspended |
| `language_code` | String | ISO language code representing the user's primary interface language |
| `reputation_score` | Float | Calculated metric (0.0-5.0) representing account trustworthiness and engagement quality |
| `last_seen` | String (ISO 8601) | UTC timestamp of the most recent account activity detected |
| `profile_stats.followers` | Integer | Total count of accounts following this user |
| `profile_stats.following` | Integer | Total count of accounts this user follows |
| `profile_stats.total_posts` | Integer | Cumulative number of tweets posted by the user |
| `profile_stats.avg_engagement_rate` | Float | Average engagement rate (%) calculated across recent posts |
| `location.city` | String | User-declared or inferred city of residence |
| `location.country` | String | ISO 3166-1 alpha-2 country code |
| `location.timezone` | String | IANA timezone identifier for the user's location |
| `location.coordinates.latitude` | Float | Geographic latitude coordinate |
| `location.coordinates.longitude` | Float | Geographic longitude coordinate |
| `security.two_factor_enabled` | Boolean | Indicates whether two-factor authentication is active on the account |
| `security.last_password_change` | String (ISO 8601) | UTC timestamp of the most recent password modification |
| `security.login_attempts` | Integer | Number of failed login attempts detected in recent period |
| `security.security_score` | Float | Normalized security posture score (0.0-1.0) based on authentication practices |
| `account_type` | String | Account tier classification (e.g., ""premium"", ""basic"", ""business"") |
| `email_hash` | String | One-way cryptographic hash of the associated email address |
| `sentiment_score` | Float | Aggregate sentiment score (-1.0 to 1.0) derived from recent tweet content analysis |

### Sample Dataset

Below is a sample of the high-fidelity JSON output:

```json
{
  ""user_id"": ""u_789456123"",
  ""username"": ""tech_explorer"",
  ""external_id"": ""usr_7894561230123456789"",
  ""scraped_at"": ""2025-12-21T12:00:00Z"",
  ""account_created"": ""2020-03-15T08:22:31Z"",
  ""is_verified"": true,
  ""is_active"": true,
  ""language_code"": ""en_US"",
  ""reputation_score"": 4.8,
  ""last_seen"": ""2025-12-20T23:15:42Z"",
  ""profile_stats"": {
    ""followers"": 12456,
    ""following"": 891,
    ""total_posts"": 567,
    ""avg_engagement_rate"": 3.2
  },
  ""location"": {
    ""city"": ""San Francisco"",
    ""country"": ""US"",
    ""timezone"": ""America/Los_Angeles"",
    ""coordinates"": {
      ""latitude"": 37.7749,
      ""longitude"": -122.4194
    }
  },
  ""security"": {
    ""two_factor_enabled"": true,
    ""last_password_change"": ""2025-11-30T14:22:10Z"",
    ""login_attempts"": 1,
    ""security_score"": 0.95
  },
  ""account_type"": ""premium"",
  ""email_hash"": ""d4c3b2a1e5f6g7h8i9j0"",
  ""sentiment_score"": 0.75
}
````

### Configuration Parameters

To ensure optimal data depth, configure the following:

| Parameter | JSON Field Name | Data Type | Required | Description | Example Value |
|-----------|----------------|-----------|----------|-------------|---------------|
| Username | `username` | String | Yes | Twitter handle to extract (without @ symbol) | `""elonmusk""` |

### Analytical Use Cases

**Lead Enrichment & Qualification**: Sales intelligence teams can augment CRM records with follower counts, verification status, and engagement metrics to prioritize high-value prospects and tailor outreach messaging based on account tier and activity patterns.

**Sentiment Analysis**: Data scientists can leverage the `sentiment_score` field alongside `profile_stats` to correlate user sentiment with engagement behaviors, identifying brand advocates or detractors for targeted marketing campaigns.

**Network Mapping & Influence Analysis**: Researchers can construct social graphs using `followers` and `following` counts combined with `reputation_score` to identify key opinion leaders and information diffusion pathways within specific communities.

**Temporal Behavior Studies**: Longitudinal analysis of `last_seen`, `account_created`, and `total_posts` enables cohort analysis and user lifecycle modeling to understand platform engagement evolution over time.

**Geographic Market Segmentation**: Location data (`city`, `country`, `coordinates`) facilitates regional market analysis and geo-targeted campaign planning for sales and marketing operations.

**Security Posture Assessment**: Enterprise security teams can evaluate `security_score` and `two_factor_enabled` metrics to assess risk profiles when vetting potential business partners or monitoring brand impersonation threats.

### Technical Limitations

**Important Considerations**:

- **Rate Limiting**: Extraction throughput is subject to platform-imposed rate limits; batch processing of large username lists may require throttling to maintain data integrity.
- **Data Freshness**: The `scraped_at` timestamp reflects extraction time; rapidly changing metrics (e.g., `followers`, `last_seen`) may exhibit minor staleness depending on extraction frequency.
- **Location Accuracy**: Geographic coordinates are derived from user-declared location strings and may not reflect precise physical locations; accuracy varies based on profile completeness.
- **Suspended Accounts**: Profiles with `is_active: false` return limited metadata; certain fields (e.g., `profile_stats`, `last_seen`) may be null or stale.
- **Privacy-Protected Accounts**: Private/protected accounts return only publicly visible metadata; follower counts and engagement metrics may be unavailable.
- **Sentiment Score Methodology**: The `sentiment_score` is calculated from recent tweet content (typically last 100 tweets) and may not represent long-term account sentiment trends.
- **Email Hash Availability**: The `email_hash` field is populated only when email information is publicly exposed or inferrable; null values are common.

***

**Keywords & Tags**: This specification supports username scraper, get user by username, profile scraper tool, export user profiles, social media username lookup, lead generation scraper, and profile data extraction workflows for sales intelligence and data enrichment operations."

# Actor input Schema

## `username` (type: `string`):

Username

## Actor input object example

```json
{
  "username": "elonmusk"
}
```

# 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 = {
    "username": "elonmusk"
};

// Run the Actor and wait for it to finish
const run = await client.actor("patient_discovery/twitter-user").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 = { "username": "elonmusk" }

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

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

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

```

## CLI example

```bash
echo '{
  "username": "elonmusk"
}' |
apify call patient_discovery/twitter-user --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=patient_discovery/twitter-user",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Twitter User By Username",
        "description": "Get Twitter user by username.",
        "version": "1.0",
        "x-build-id": "EaKBNJTcu3eZbMRe5"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/patient_discovery~twitter-user/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-patient_discovery-twitter-user",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/patient_discovery~twitter-user/runs": {
            "post": {
                "operationId": "runs-sync-patient_discovery-twitter-user",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/patient_discovery~twitter-user/run-sync": {
            "post": {
                "operationId": "run-sync-patient_discovery-twitter-user",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "username"
                ],
                "properties": {
                    "username": {
                        "title": "Username",
                        "type": "string",
                        "description": "Username",
                        "default": "elonmusk"
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
