# Instagram Hashtag Scraper — Hashtag & Keyword Posts (`thenetaji/instagram-hashtag-scraper`) Actor

Find Instagram posts and reels by hashtag or keyword. Each row carries the post code, like and comment counts, publish date and media type, with full media detail on request.

- **URL**: https://apify.com/thenetaji/instagram-hashtag-scraper.md
- **Developed by:** [The Netaji](https://apify.com/thenetaji) (community)
- **Categories:** Social media, Marketing, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.25 / 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/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 Hashtag Scraper

The Actor finds public Instagram posts and reels by hashtag, or by a keyword matched against posts or against reels, and saves one row per result. Each row carries the shortcode, like and comment counts, publish time and media type; results that arrive with incomplete data can be completed with a full media lookup.

### Accepted input

- `scraperType`: `hashtagMedia` searches a hashtag, `postsByKeyword` searches posts by keyword and `reelsByKeyword` searches reels by keyword. The default is `hashtagMedia`.
- `hashtag`: the hashtag without `#`. Required in `hashtagMedia` mode.
- `keyword`: the search words. Required in the two keyword modes.
- `tab`: `recent` or `top`, applied in `hashtagMedia` mode only. The default is `recent`.
- `limit`: the total number of results saved. The default is `100`; `0` collects everything the search returns.
- `addonMediaDetails`: replaces each result with its full media record. The default is `false`.

```json
{
  "scraperType": "hashtagMedia",
  "hashtag": "streetphotography",
  "tab": "top",
  "limit": 200
}
```

### Response fields

- `code` and `pk`: the shortcode and numeric ID of the post or reel.
- `like_count` and `comment_count`: the counts at the moment of collection.
- `taken_at`: the publish time as a Unix timestamp in seconds.
- `media_type`: `1` for a photo, `2` for a video and `8` for a carousel.
- `enriched`: `true` when the row was replaced with the full media record.

```json
{
  "pk": "4032438367452261373",
  "code": "Df2GVSWpev9",
  "like_count": 5530,
  "comment_count": 170,
  "taken_at": 1794924316,
  "media_type": 1,
  "enriched": true
}
```

### Behaviour on partial results

Search pages are read until the `limit` is reached or Instagram stops returning further pages. The run ends at whichever comes first, so a `limit` of `0` returns as many results as Instagram serves for the search rather than every post ever tagged. A run in `hashtagMedia` mode without a `hashtag`, or in a keyword mode without a `keyword`, stops with an error before any request is made.

When `addonMediaDetails` is enabled, the lookup runs only on results within the `limit`, and each lookup is charged once after it succeeds. A result whose full record cannot be read is left out of the dataset and is not charged.

### Frequently asked questions

**What is the difference between `recent` and `top`?**
`recent` follows the hashtag feed in publishing order; `top` follows the posts Instagram ranks highest for the hashtag, which are not ordered by date.

**Which accounts posted the results?**
Rows identify posts, not authors. The shortcodes can be passed to the [Instagram Post Details Scraper](https://apify.com/thenetaji/instagram-post-details-scraper) or the [Instagram Comments Scraper](https://apify.com/thenetaji/instagram-media-comments-scraper) for further detail on each post.

# Actor input Schema

## `scraperType` (type: `string`):

A hashtag, or a keyword matched against posts or reels.

## `hashtag` (type: `string`):

The hashtag without #. Used when searching by hashtag.

## `keyword` (type: `string`):

Words to match. Used when searching posts or reels by keyword.

## `tab` (type: `string`):

Most recent or top posts for the hashtag.

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

How many posts to return. 0 returns everything available.

## `addonMediaDetails` (type: `boolean`):

Fetch full details for results that come back thin. Charged once per post.

## Actor input object example

```json
{
  "scraperType": "hashtagMedia",
  "hashtag": "tokyo",
  "keyword": "tokyo",
  "tab": "recent",
  "limit": 100,
  "addonMediaDetails": false
}
```

# Actor output Schema

## `dataset` (type: `string`):

All records scraped by this run

# 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 = {
    "hashtag": "tokyo",
    "keyword": "tokyo"
};

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

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

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,thenetaji/instagram-hashtag-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/UZFLHwA7k5wZHncVB/builds/0P0FAPG8AaSmHdtZD/openapi.json
