# Instagram Posts Scraper (`outspoken_strategy/instagram-posts-scraper`) Actor

Scrape posts and reels from any Instagram profile (e.g. instagram.com/meta) with a start/end date filter. Returns caption, hashtags, likes, comments, views, media URLs, location, tagged users, music and profile stats. Requires a session (cookies or automated login).

- **URL**: https://apify.com/outspoken_strategy/instagram-posts-scraper.md
- **Developed by:** [code craker](https://apify.com/outspoken_strategy) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 2 monthly users, 90.5% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $8.00 / 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.

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

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

## Instagram Posts Scraper

Apify actor that scrapes the posts of one or more Instagram profiles
(e.g. `https://www.instagram.com/meta`) with an optional start/end date filter.

**A session is required.** Instagram only serves profile posts to logged-in sessions. The
actor authenticates in priority order:

1. `cookies` input — a JSON cookie export from a logged-in browser (Cookie-Editor /
   EditThisCookie); the `sessionid` cookie carries the session
2. `IG_COOKIES` secret env var on the actor (same JSON, or a `name=value; ...` string)
3. the cached session in the `instagram-session` key-value store (needs full permissions)
4. automated login with `igUsername`/`igPassword` (or `IG_USERNAME`/`IG_PASSWORD`)

**Always use a throwaway account.** Optionally set `IG_PROXY_SESSION` (e.g. `igacct1`) so
the account keeps one exit IP across runs.

### How it works

A real Chrome (Playwright) opens each profile with the session. The posts the page loads
itself (embedded in the HTML and from its `PolarisProfilePostsQuery` GraphQL call) are
taken first. The actor then scrolls once so the page sends its own pagination query
(`PolarisProfilePostsTabContentQuery_connection`) and replays that request with the
`end_cursor` from each page, 12 posts per request, newest first. If replaying fails it
falls back to scrolling the profile page.

The grid data has no view counts, location or alt text, so with `enrichPosts` on (the
default) each kept post is also fetched from `/api/v1/media/{id}/info/`. If Instagram
rate-limits these requests, enrichment turns off for the rest of the run and posts are
still saved.

Profile details (followers, following, posts, verified, business) come from the profile
page's own query.

### Input

```json
{
    "profileUrls": ["https://www.instagram.com/meta", "@nasa", "natgeo"],
    "numberOfPosts": 50,
    "start_date": "2026-08-01",
    "end_date": "2026-08-31",
    "includePinned": true,
    "enrichPosts": true,
    "proxyConfiguration": { "useApifyProxy": true, "apifyProxyGroups": ["RESIDENTIAL"], "apifyProxyCountry": "US" }
}
```

- Profiles can be URLs, `@username` or plain usernames. Post or reel URLs are rejected.
  `profileUrl` (single) and `usernames` are also accepted.
- `numberOfPosts` is **per profile** (alias `resultsLimit`, max 5,000). `scrapeAll: false`
  takes only the first page.
- `start_date` / `end_date` (yyyy-mm-dd, inclusive, UTC) filter on each post's publish
  time. The feed is newest first, so the actor stops at the first post older than
  `start_date`. Pinned posts are out of order, so they are checked individually and never
  end the scan. Aliases: `timeSince` / `timeUntil`.
- `includePinned: false` drops posts pinned to the top of the grid.
- `debug: true` saves Instagram's responses, a screenshot and the HTML to the run's
  key-value store.

### Output

One dataset item per post (abridged):

```json
{
    "id": "4007130457085500194",
    "code": "DecL-uHOtsi",
    "url": "https://www.instagram.com/reel/DecL-uHOtsi/",
    "text": "@nataszko is an illustrator who ...",
    "hashtags": [],
    "mentions": ["nataszko"],
    "created_at": "2026-10-13T16:05:30.000Z",
    "createdUtc": 1791907530,
    "mediaType": "video",
    "productType": "clips",
    "isVideo": true,
    "isReel": true,
    "likes": 102781,
    "comments": 4412,
    "views": 1543210,
    "reshares": 2295,
    "videoDuration": 61.077,
    "videoUrl": "https://scontent...mp4",
    "displayUrl": "https://scontent...jpg",
    "images": ["https://scontent...jpg"],
    "childPosts": [],
    "carouselCount": null,
    "music": { "title": "Original audio", "artist": "meta", "audioId": "..." },
    "location": null,
    "taggedUsers": [{ "username": "nataszko", "fullName": "Natasha Polozenko", "userId": "..." }],
    "coauthors": [{ "username": "nataszko", "fullName": "Natasha Polozenko", "userId": "..." }],
    "isPinned": false,
    "isPinnedInReelsTab": false,
    "isPaidPartnership": false,
    "commentsDisabled": false,
    "likesHidden": false,
    "username": "meta",
    "fullName": "Meta",
    "userId": "28247116907",
    "isVerified": true,
    "profileUsername": "meta",
    "profileFullName": "Meta",
    "profileFollowersCount": 6321603,
    "profileFollowingCount": 35,
    "profilePostsCount": 1804,
    "profileIsVerified": true,
    "profileIsBusiness": true,
    "profileUrl": "https://www.instagram.com/meta/",
    "inputUrl": "https://www.instagram.com/meta",
    "scrapedAt": "2026-11-06T11:25:13.000Z"
}
```

- `username` is the post's author. Collab posts on the profile's grid can have another
  author; `profileUsername` is always the scraped profile.
- `views` is `null` for photos (and for videos when enrichment is off or rate-limited).
- Each profile's details are also saved to the key-value store as `PROFILE_<username>`.

### Local development

```bash
npm install
mkdir -p storage/key_value_stores/default
cat > storage/key_value_stores/default/INPUT.json <<'JSON'
{ "profileUrl": "https://www.instagram.com/meta", "numberOfPosts": 20,
  "cookies": [ ...exported from a logged-in browser... ],
  "proxyConfiguration": { "useApifyProxy": false } }
JSON
npm start
```

Deploy with `apify push`.

# Actor input Schema

## `profileUrl` (type: `string`):

The Instagram profile to scrape, e.g. https://www.instagram.com/meta. A username ("meta" or "@meta") works too.

## `profileUrls` (type: `array`):

Several profiles to scrape — each is scraped separately and results are combined. "Number of posts" applies PER profile.

## `numberOfPosts` (type: `integer`):

Maximum number of posts to return per profile (after date filtering).

## `scrapeAll` (type: `boolean`):

Keep paging until the target count is reached, the date range is passed, or the profile runs out of posts. When unchecked only the first page (12 posts) is fetched.

## `start_date` (type: `string`):

Only return posts published on or after this date (format: yyyy-mm-dd).

## `end_date` (type: `string`):

Only return posts published on or before this date, inclusive (format: yyyy-mm-dd).

## `includePinned` (type: `boolean`):

Pinned posts sit at the top of a profile regardless of age. Uncheck to always exclude them.

## `cookies` (type: `array`):

Cookies of a logged-in Instagram session exported with Cookie-Editor / EditThisCookie (JSON array). The "sessionid" cookie carries the session. Alternatively set the IG_COOKIES env var.

## `igUsername` (type: `string`):

Throwaway account username (2FA off), used only when no valid cookies are available. Prefer the IG_USERNAME env var.

## `igPassword` (type: `string`):

Password for igUsername. Prefer the IG_PASSWORD secret env var.

## `timeSince` (type: `string`):

Alias of start_date, matching the Facebook profile posts actor.

## `timeUntil` (type: `string`):

Alias of end_date.

## `resultsLimit` (type: `integer`):

Alias of numberOfPosts for integrations built against other Instagram actors.

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

Alias of profileUrls.

## `proxySessionId` (type: `string`):

Stable id (or the IG_PROXY_SESSION env var) to keep the account on ONE exit IP across runs — Instagram flags sessions that hop IPs. One id per account, e.g. "igacct1".

## `proxyConfiguration` (type: `object`):

Residential proxies with a fixed country are strongly recommended; Instagram blocks datacenter IPs.

## `enrichPosts` (type: `boolean`):

The profile grid omits view/play counts, location and alt text. With this on, the actor requests each kept post's full details (one extra request per post, so runs are slower). Turned off automatically if Instagram rate-limits the requests.

## `headless` (type: `boolean`):

Uncheck only for local debugging.

## `debug` (type: `boolean`):

Save Instagram API/GraphQL responses, a screenshot and the page HTML to the run's key-value store. For troubleshooting.

## Actor input object example

```json
{
  "profileUrl": "https://www.instagram.com/meta",
  "numberOfPosts": 25,
  "scrapeAll": true,
  "includePinned": true,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  },
  "enrichPosts": true,
  "headless": true,
  "debug": false
}
```

# Actor output Schema

## `posts` (type: `string`):

All scraped posts, one item per post.

## `postsOverview` (type: `string`):

Overview view: post, profile, caption, likes, comments, views, date.

## `profiles` (type: `string`):

Key-value store with PROFILE\_<username> records (bio, followers, posts count...) and debug files.

# 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 = {
    "profileUrl": "https://www.instagram.com/meta",
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ],
        "apifyProxyCountry": "US"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("outspoken_strategy/instagram-posts-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 = {
    "profileUrl": "https://www.instagram.com/meta",
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "US",
    },
}

# Run the Actor and wait for it to finish
run = client.actor("outspoken_strategy/instagram-posts-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 '{
  "profileUrl": "https://www.instagram.com/meta",
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  }
}' |
apify call outspoken_strategy/instagram-posts-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,outspoken_strategy/instagram-posts-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/iygRhPcGb0eaAjGTA/builds/OlDOOSdV4xhtkCqfs/openapi.json
