# Instagram Video Scraper (`social_media_scraper/instagram-video-scraper`) Actor

Scrape data from Instagram video.

- **URL**: https://apify.com/social_media_scraper/instagram-video-scraper.md
- **Developed by:** [Social Media Scraper](https://apify.com/social_media_scraper) (community)
- **Categories:** Social media
- **Stats:** 130 total users, 0 monthly users, 100.0% runs succeeded, 2 bookmarks
- **User rating**: 1.00 out of 5 stars

## Pricing

$9.99 / 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 Stats Actor

An [Apify](https://apify.com) actor that fetches statistical data from Instagram posts using the Apify Instagram Scraper. This actor retrieves view counts, play counts, likes, and comments for Instagram posts.

### Features

- Fetches comprehensive statistics for Instagram posts
- Handles timeouts and retries automatically
- Provides structured output data
- Supports both single post URLs and batch processing
- Includes detailed error handling and logging

### Prerequisites

- Python 3.7 or later
- Apify SDK
- Valid Apify API token
- Instagram Apify API token

### Installation

1. Clone this repository or download the source files

```bash
git clone <repository-url>
cd instagram-stats-actor
```

2. Install required dependencies

```bash
pip install apify-client httpx tenacity
```

### Usage

#### Running as Apify Actor

1. Input Schema:

```json
{
    "url": "https://www.instagram.com/p/example"
}
```

2. Example output:

```json
{
    "url": "https://www.instagram.com/p/example",
    "shortCode": "example",
    "statistics": {
        "views": 1000,
        "plays": 950,
        "likes": 500,
        "comments": 50
    },
    "success": true
}
```

### Configuration Options

| Parameter | Type | Description | Default |
|-----------|------|-------------|---------|
| timeout | int | Request timeout in seconds | 30 |
| max_retries | int | Maximum number of retry attempts | 3 |

### Error Handling

The actor implements comprehensive error handling:

- Timeouts: Automatically retries with exponential backoff
- API Errors: Detailed error messages in the output
- Invalid URLs: Validation and meaningful error messages
- Network Issues: Automatic retry mechanism

### Examples

#### Basic Actor Input

```json
{
    "url": "https://www.instagram.com/p/example"
}
```

#### Custom Configuration Input

```json
{
    "url": "https://www.instagram.com/p/example",
    "timeout": 60,
    "maxRetries": 5
}
```

#### Success Output Example

```json
{
    "url": "https://www.instagram.com/p/example",
    "shortCode": "example",
    "statistics": {
        "views": 1000,
        "plays": 950,
        "likes": 500,
        "comments": 50
    },
    "success": true
}
```

#### Error Output Example

```json
{
    "url": "https://www.instagram.com/p/example",
    "error": "Request timed out after 30 seconds",
    "success": false
}
```

### License

This project is licensed under the MIT License - see the LICENSE file for details.

# Actor input Schema

## `url` (type: `string`):

The URL of website you want to get the data from.

## Actor input object example

```json
{
  "url": "https://www.instagram.com/reel/DBJohtht0-d/"
}
```

# 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 = {
    "url": "https://www.instagram.com/reel/DBJohtht0-d/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("social_media_scraper/instagram-video-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 = { "url": "https://www.instagram.com/reel/DBJohtht0-d/" }

# Run the Actor and wait for it to finish
run = client.actor("social_media_scraper/instagram-video-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 '{
  "url": "https://www.instagram.com/reel/DBJohtht0-d/"
}' |
apify call social_media_scraper/instagram-video-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,social_media_scraper/instagram-video-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/lUGNW8Oi8VlKmLvjs/builds/3yEFDRii0fYuOORJD/openapi.json
