# Facebook & Instagram Ad Library Scraper (Meta) (`straightforward_hydra/meta-ad-library-scraper`) Actor

Search every ad running on Facebook, Instagram, Messenger and Audience Network via Meta's official Ad Library API. Filter by keyword, page, country, date, platform and media type. Political ads include spend and impressions.

- **URL**: https://apify.com/straightforward\_hydra/meta-ad-library-scraper.md
- **Developed by:** [Dev D](https://apify.com/straightforward_hydra) (community)
- **Categories:** Social media, Other, Automation
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $6.00 / 1,000 ads

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

## Meta Ad Library Scraper (Facebook & Instagram Ads)

Every ad running on **Facebook, Instagram, Messenger and Audience Network**, from Meta's **official Ad Library API**.

Most Meta ad scrapers scrape the Ad Library *website* and break whenever Meta changes it. This one uses the sanctioned API — the same source Meta publishes for DSA compliance — so it returns stable JSON instead of fighting anti-bot measures.

### What you get

| Field | Description |
|---|---|
| `page_name` / `page_id` | The advertiser |
| `ad_body` / `ad_title` / `ad_description` / `ad_caption` | The creative copy |
| `creative_count` | How many creative variations the ad carries |
| `delivery_start` / `delivery_stop` / `is_active` | When it ran, and whether it still is |
| `platforms` | Facebook, Instagram, Messenger, Audience Network |
| `languages` / `target_ages` / `target_gender` / `target_locations` | Targeting as disclosed |
| `eu_total_reach` | People reached in the EU |
| `snapshot_url` / `ad_library_url` | See the ad itself |
| `spend_lower` / `spend_upper`, `impressions_*`, `demographic_distribution` | Political & issue ads only |

### You need a Meta access token

Meta restricts the Ad Library API to verified developer accounts:

1. Create an app at [developers.facebook.com](https://developers.facebook.com)
2. Complete Meta's identity verification (one-off, can take a day or two)
3. Copy a token from the Graph API Explorer and paste it into `accessToken`

The token is stored as a secret and is only ever sent to Meta. Tokens expire — regenerate if you see an auth error.

### Input

```json
{
  "accessToken": "<your token>",
  "searchTerms": ["nike", "adidas"],
  "countries": ["US", "GB"],
  "adActiveStatus": "ACTIVE",
  "maxResults": 500
}
```

| Option | Default | Notes |
|---|---|---|
| `accessToken` | – | **Required.** Your own Meta token |
| `searchTerms` | `["nike"]` | Searched separately; results split evenly |
| `pageIds` | – | Search specific advertiser pages instead of keywords |
| `countries` | `["US"]` | **Required by Meta** — the country the ad reached |
| `adType` | `ALL` | Or the regulated verticals: political, housing, employment, credit |
| `adActiveStatus` | `ALL` | `ACTIVE` for currently-running ads only |
| `mediaType` | `ALL` | Image, video, meme, or none |
| `languages` | – | e.g. `en`, `es` |
| `deliveryDateMin` / `Max` | – | `YYYY-MM-DD` |
| `includeSpendAndImpressions` | `false` | See below |
| `maxResults` | `100` | Split across search terms |

### Notes

- **Spend, impressions and demographics exist only for political & issue ads.** That is Meta's rule, not ours. Turn on `includeSpendAndImpressions` *and* set `adType` to `POLITICAL_AND_ISSUE_ADS` together — asking for those fields on a general search makes Meta reject the request.
- `countries` is mandatory: Meta's archive is indexed by the country an ad reached.
- If a run returns nothing, widen the date range or set `adActiveStatus` to `ALL` — stopped ads are excluded by some filters.
- Large runs should raise `maxResults` **and** the run timeout together. If the run would exceed its timeout, the Actor stops cleanly and keeps everything collected so far rather than failing.

### Pricing

Pay per event: `ad` — one ad from the archive.

# Actor input Schema

## `accessToken` (type: `string`):

Your own Meta access token. Create an app at developers.facebook.com, complete identity verification, then copy a token from the Graph API Explorer. Stored as a secret and sent only to Meta.

## `searchTerms` (type: `array`):

Keywords to search ad text for, e.g. "nike", "black friday". Each term is searched separately.

## `pageIds` (type: `array`):

Search specific advertiser pages by Facebook page ID instead of by keyword. Combined into one query.

## `countries` (type: `array`):

ISO country codes the ad reached, e.g. US, GB, DE. Meta requires at least one.

## `adType` (type: `string`):

ALL covers every ad. The other categories are Meta's regulated verticals — political/issue ads are the only ones that expose spend and impressions.

## `adActiveStatus` (type: `string`):

Whether to include ads that have stopped running.

## `mediaType` (type: `string`):

Restrict to a creative format.

## `languages` (type: `array`):

Restrict to ads in these languages, e.g. en, es, de.

## `deliveryDateMin` (type: `string`):

Only ads delivered on or after this date (YYYY-MM-DD).

## `deliveryDateMax` (type: `string`):

Only ads delivered on or before this date (YYYY-MM-DD).

## `includeSpendAndImpressions` (type: `boolean`):

Adds spend ranges, impression ranges, audience size and demographic breakdowns. Meta only releases these for political & issue ads — set Ad category to "Political & issue ads" as well, or the request is rejected.

## `maxResults` (type: `integer`):

Total ads to collect, split evenly across your search terms.

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

Optional. The Graph API does not need a proxy.

## Actor input object example

```json
{
  "searchTerms": [
    "nike",
    "adidas"
  ],
  "countries": [
    "US",
    "GB"
  ],
  "adType": "ALL",
  "adActiveStatus": "ALL",
  "mediaType": "ALL",
  "includeSpendAndImpressions": false,
  "maxResults": 100,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# 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 = {
    "searchTerms": [
        "nike",
        "adidas"
    ],
    "countries": [
        "US",
        "GB"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("straightforward_hydra/meta-ad-library-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 = {
    "searchTerms": [
        "nike",
        "adidas",
    ],
    "countries": [
        "US",
        "GB",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("straightforward_hydra/meta-ad-library-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 '{
  "searchTerms": [
    "nike",
    "adidas"
  ],
  "countries": [
    "US",
    "GB"
  ]
}' |
apify call straightforward_hydra/meta-ad-library-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,straightforward_hydra/meta-ad-library-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/Lt0HXs7i6alKZO3aR/builds/nKwLDTNwxJfuTqKZa/openapi.json
