# Instagram Scraper (`thisismegant/instagram-scraper`) Actor

- **URL**: https://apify.com/thisismegant/instagram-scraper.md
- **Developed by:** [Megan Studios](https://apify.com/thisismegant) (community)
- **Categories:** Automation, Developer tools, Social media
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## 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/platform/actors/running/actors-in-store#pay-per-usage

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

## Instagram Scraper

Scrape Instagram profiles, posts, reels, and comments from one Apify Actor.

This Actor is designed for authenticated scraping. The Instagram session cookies
are configured by the Actor owner as an environment variable, so regular users
only need to choose what to scrape and provide usernames or post IDs.

### What You Can Scrape

- Profile details such as biography, follower counts, profile picture, verified status, and external URL.
- Posts and reels with captions, hashtags, mentions, media URLs, structured media assets, timestamps, likes, comments count, and available playback metrics.
- Comments with username, text, likes, reply count, pinned status, and verified status.
- Combined collection using the `all` mode.

### Input

#### scrapeType

Choose what the Actor should collect:

- `profile` - scrape profile information for each username.
- `posts` - scrape posts and reels for each username.
- `reels` - scrape video/reel media only.
- `comments` - scrape comments from `postIds`, or resolve posts from `usernames` first.
- `all` - scrape profile, posts/reels, and comments in one run.

#### usernames

Instagram usernames to scrape. Do not include `@`.

Required for `profile`, `posts`, `reels`, and `all`. For `comments`, this is optional if `postIds` are provided.

Default: `["wander_worldly"]`

#### postIds

Numeric Instagram media IDs used for comment scraping.

If `scrapeType` is `comments` and `postIds` is empty, the Actor will fetch posts from `usernames` first and then scrape comments for those posts.

#### limit

Maximum number of posts or reels to scrape or inspect per username.

Default: `20`

#### commentsLimit

Maximum number of comments to scrape per post.

Default: `50`

#### outputPath and outputFormat

Optional local file output for self-hosted/local runs. Apify runs always write results to the default Dataset.

Supported formats:

- `json`
- `jsonl`
- `csv`

### Example Inputs

#### Profile

```json
{
  "scrapeType": "profile",
  "usernames": ["wander_worldly"]
}
````

#### Posts and Reels

```json
{
  "scrapeType": "posts",
  "usernames": ["wander_worldly"],
  "limit": 10
}
```

#### Reels Only

```json
{
  "scrapeType": "reels",
  "usernames": ["wander_worldly"],
  "limit": 10
}
```

#### Comments by Post ID

```json
{
  "scrapeType": "comments",
  "postIds": ["3931648135231633082"],
  "commentsLimit": 50
}
```

#### All Data

```json
{
  "scrapeType": "all",
  "usernames": ["wander_worldly"],
  "limit": 5,
  "commentsLimit": 20
}
```

### Example Output

#### Profile

```json
{
  "recordType": "profile",
  "id": "61423648970",
  "username": "wander_worldly",
  "fullName": "Wander Worldly",
  "biography": "Global journeys and travel moments",
  "followersCount": 360,
  "followingCount": 308,
  "postsCount": 390,
  "profilePicUrl": "https://...",
  "isVerified": false,
  "businessCategoryName": "None"
}
```

#### Post or Reel

```json
{
  "recordType": "reel",
  "id": "3931648135231633082",
  "shortcode": "DaQBSXyTva6",
  "mediaType": 2,
  "productType": "clips",
  "ownerId": "61423648970",
  "ownerUsername": "wander_worldly",
  "caption": "Caption text with #hashtags",
  "hashtags": ["travel", "world"],
  "mentions": [],
  "media": [
    {
      "type": "thumbnail",
      "url": "https://...",
      "width": 640,
      "height": 1138
    },
    {
      "type": "video",
      "url": "https://...",
      "width": 720,
      "height": 1280,
      "duration": 17.5,
      "bandwidth": 123456
    }
  ],
  "mediaUrls": ["https://..."],
  "isVideo": true,
  "thumbnailUrl": "https://...",
  "timestamp": 1782909029,
  "publishedAtMs": 1782909029000,
  "publishedAt": "2026-07-01T00:30:29.000Z",
  "likesCount": 0,
  "commentsCount": 0,
  "playsCount": 1234,
  "viewsCount": 1200,
  "sharesCount": 12,
  "repostsCount": 3,
  "savesCount": 8,
  "taggedUsers": []
}
```

Some engagement metrics, such as shares and reposts, are included only when Instagram returns them in the authenticated response.

#### Comment

```json
{
  "recordType": "comment",
  "postId": "3931648135231633082",
  "id": "18000000000000000",
  "username": "example_user",
  "text": "Great post!",
  "likesCount": 3,
  "repliesCount": 0,
  "timestamp": 1782909999,
  "isPinned": false,
  "isVerified": false
}
```

### Authentication

This Actor requires Instagram cookies configured by the Actor owner.

Set the environment variable:

```text
INSTAGRAM_COOKIES=sessionid=...; ds_user_id=...; csrftoken=...
```

Store it as a secret environment variable. Do not expose session cookies in Actor input, public documentation, logs, or examples.

### Limits and Notes

- Instagram may rate-limit or block requests depending on account trust, request volume, region, and proxy quality.
- Private profiles, deleted posts, restricted content, or unavailable media may not be returned.
- Media URLs can expire because Instagram CDN links are time-limited.
- Counts and engagement metrics reflect what Instagram returns at scrape time.
- Using one shared Instagram session for many users can increase rate-limit risk.

### Troubleshooting

#### The Actor says cookies are required

Set `INSTAGRAM_COOKIES` in the Actor environment variables.

#### The Actor returns login or checkpoint errors

Refresh the Instagram cookies. The session may be expired, challenged, or rate-limited.

#### Shares or reposts are missing

Instagram does not always return these metrics in the endpoint response. The Actor includes them only when available.

#### Dataset is empty

Check that the input contains valid usernames or post IDs, then inspect the run log for authentication or rate-limit messages.

### For Developers

Technical setup, monorepo structure, Docker, and local development notes are available in `docs/DEVELOPMENT.md`.

Release history is available in `CHANGELOG.md`.

# Actor input Schema

## `scrapeType` (type: `string`):

Choose which Instagram data to scrape.

## `usernames` (type: `array`):

Instagram usernames. Required for profile, posts, reels, all, and optional for comments.

## `postIds` (type: `array`):

Optional numeric Instagram media IDs for comment scraping. If omitted for comments, posts are resolved from usernames.

## `limit` (type: `integer`):

Maximum number of posts/reels to scrape or inspect per username.

## `commentsLimit` (type: `integer`):

Maximum number of comments to scrape per post.

## `outputPath` (type: `string`):

Optional local file path for JSON, JSONL, or CSV output.

## `outputFormat` (type: `string`):

Optional local output format. If omitted, it is inferred from outputPath.

## Actor input object example

```json
{
  "scrapeType": "profile",
  "usernames": [
    "wander_worldly"
  ],
  "limit": 20,
  "commentsLimit": 50
}
```

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("thisismegant/instagram-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("thisismegant/instagram-scraper").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 '{}' |
apify call thisismegant/instagram-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Instagram Scraper",
        "version": "0.0",
        "x-build-id": "J7fYkOTIWP9B97KJC"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/thisismegant~instagram-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-thisismegant-instagram-scraper",
                "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/thisismegant~instagram-scraper/runs": {
            "post": {
                "operationId": "runs-sync-thisismegant-instagram-scraper",
                "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/thisismegant~instagram-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-thisismegant-instagram-scraper",
                "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": [
                    "scrapeType"
                ],
                "properties": {
                    "scrapeType": {
                        "title": "Scrape type",
                        "enum": [
                            "profile",
                            "posts",
                            "reels",
                            "comments",
                            "all"
                        ],
                        "type": "string",
                        "description": "Choose which Instagram data to scrape.",
                        "default": "profile"
                    },
                    "usernames": {
                        "title": "Usernames",
                        "type": "array",
                        "description": "Instagram usernames. Required for profile, posts, reels, all, and optional for comments.",
                        "items": {
                            "type": "string"
                        },
                        "default": [
                            "wander_worldly"
                        ]
                    },
                    "postIds": {
                        "title": "Post IDs",
                        "type": "array",
                        "description": "Optional numeric Instagram media IDs for comment scraping. If omitted for comments, posts are resolved from usernames.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "limit": {
                        "title": "Posts limit",
                        "minimum": 1,
                        "maximum": 500,
                        "type": "integer",
                        "description": "Maximum number of posts/reels to scrape or inspect per username.",
                        "default": 20
                    },
                    "commentsLimit": {
                        "title": "Comments limit",
                        "minimum": 1,
                        "maximum": 1000,
                        "type": "integer",
                        "description": "Maximum number of comments to scrape per post.",
                        "default": 50
                    },
                    "outputPath": {
                        "title": "Local output path",
                        "type": "string",
                        "description": "Optional local file path for JSON, JSONL, or CSV output."
                    },
                    "outputFormat": {
                        "title": "Local output format",
                        "enum": [
                            "json",
                            "jsonl",
                            "csv"
                        ],
                        "type": "string",
                        "description": "Optional local output format. If omitted, it is inferred from outputPath."
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
