# Facebook Ads Library Scraper: Meta Ad Library & Instagram Ads (`data-for-agents/facebook-ads-library-scraper`) Actor

Facebook and Instagram ads from the Meta Ad Library by keyword, page ID or Ad Library link. $0.50 per 1,000 ads; errors free. One row per ad: advertiser, ad text, headline, CTA, landing page, image and video URLs, carousel cards, start date, days running. Filters: country, status, media, dates.

- **URL**: https://apify.com/data-for-agents/facebook-ads-library-scraper.md
- **Developed by:** [Data for Agents](https://apify.com/data-for-agents) (community)
- **Categories:** Social media, Marketing
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.50 / 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/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

### What it returns

One row per ad from the **Meta Ad Library** (Facebook, Instagram, Messenger, Audience Network, Threads): advertiser and page, ad text, headline, call-to-action, landing page link, image and video URLs, carousel cards, start and end date, days running, platforms and format. Search by keyword, by advertiser page ID, or paste any Ad Library link. No login, no API token.

**Price: $0.50 per 1,000 ads.** No start fee. Error rows, ads your filters skip, ads found twice and ads in `excludeAdIds` are free: you pay only for ads delivered.

Measured on Apify (2,048 MB, 2026-11-20): 30 ads in 9 s, 50 ads in 23 s for the whole run, 757 to 828 ads from one search in 6 to 9 minutes.

### Example input

```json
{ "queries": ["running shoes"], "country": "US", "maxAds": 30 }
```

### Example output

```json
{
  "status": "ok",
  "ad_archive_id": "2113133805898508",
  "ad_library_url": "https://www.facebook.com/ads/library/?id=2113133805898508",
  "page_name": "HIKE Footwear",
  "page_id": "275270825974823",
  "is_active": true,
  "start_date": "2026-06-18",
  "days_running": 147,
  "platforms": ["facebook", "instagram", "audience_network", "messenger", "threads"],
  "display_format": "video",
  "title": "Best Pain Relief Shoe 2025!",
  "body": "After years of knee pain, I thought my running days were over. ...",
  "cta_text": "Shop now",
  "link_url": "https://offers.hike-footwear.com/l/li06",
  "video_urls": ["https://video-...fbcdn.net/..."]
}
```

### Input

| Field | What it does |
|---|---|
| `queries` | Keywords, as typed in the Ad Library search box. One search each. |
| `pageIds` | Numeric page IDs (`view_all_page_id` in an Ad Library link): every ad of one advertiser. |
| `urls` | Ad Library links copied from your browser; their filters are kept. |
| `country` | Two-letter code (US, GB, DE...) or ALL. Default ALL. |
| `maxAds` | Ads per search, 1 to 5,000. Default 50. |
| `activeStatus` | active (default), inactive or all. |
| `mediaType` | all, image, video, meme, image_and_meme, none. |
| `exactPhrase` | Match the keywords as an exact phrase. |
| `startedAfter`, `startedBefore` | Only ads that started in this date range (YYYY-MM-DD). |
| `minDaysRunning`, `maxDaysRunning` | Only ads running at least / at most this many days, e.g. 30+ for proven ads or up to 7 for new ones. |
| `excludeAdIds` | Ad Library IDs you already have: skipped, never charged. |
| `dedupe` | `ad` (default): an ad found by several searches comes once, charged once. `creative`: also one row for the same advertiser, text and link under different ad IDs. `none`: every search returns all its ads. |

Date filters are passed to the Ad Library itself, so it leaves out ads that cannot match, and every ad is checked again exactly; ads outside the range are skipped and never charged.

### Limits

- Dynamic ads (`dco`) show different text to different people; the row takes its text from the first card, and `cards` lists every variant.

- Image and video links are Facebook CDN links and expire after some days; download what you need to keep.

- Spend, impressions and reach are shown by the Ad Library for political and issue ads only.

- Very large searches stop where the Ad Library stops loading more; the run then adds a free `partial_result` row.

- One search keeps every ad it showed in memory: at the default 2,048 MB one search stops cleanly at about 750 to 830 ads with a free `low_memory` row. For more ads per search run with 4,096 MB or more, or split the search by date (`startedAfter`, `startedBefore`).

### Errors

Every error is a row with `status: "error"`, an `error_code` and a sentence saying what to do. Error rows are free.

| error_code | Meaning | Retry helps |
|---|---|---|
| `missing_input`, `invalid_input` | The input or one entry cannot be used | No, fix the input |
| `no_data` | The Ad Library has no ads for this search and filters | No, change filters |
| `blocked`, `access_restricted` | Facebook showed a check or a login page | Later |
| `rate_limited` | Facebook stopped sending more ads | Later |
| `timeout`, `network_error`, `proxy_error` | The page did not load in time | Yes |
| `partial_result` | Fewer ads than asked; the ones returned are complete | Sometimes |
| `site_changed` | The page no longer has the known shape | No, the Actor needs an update |
| `cost_limit` | Your maximum charge was reached | Raise the limit |
| `run_timeout` | The run's time limit was reached before a search | Give more time |
| `internal_error` | A bug on our side | Report it |

### FAQ

**Is it legal?** It reads the public Meta Ad Library, which anyone can open without an account. You are responsible for following Meta's terms and the law where you use the data.

**Personal data?** Rows can contain advertiser names and ad text. If you store or use personal data you need a lawful basis, such as one under GDPR.

# Changelog

This Actor's version history is a separate document: https://apify.com/data-for-agents/facebook-ads-library-scraper/changelog.md

# Actor input Schema

## `queries` (type: `array`):

Words to search in every advertiser's ads, as in the Ad Library search box. Example: running shoes. Each keyword is one search.

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

Numeric Facebook page IDs to get all ads of one advertiser: the view_all_page_id value in an Ad Library link. Example: 15087023444.

## `urls` (type: `array`):

Ad Library search links copied from the browser; their own filters are kept. Example: https://www.facebook.com/ads/library/?active_status=active\&ad_type=all\&country=US\&q=shoes

## `country` (type: `string`):

Where the ads were shown: a two-letter code such as US, GB or DE, or ALL for every country.

## `maxAds` (type: `integer`):

Stop each search after this many ads. Each ad is charged; one page of the Ad Library is about 10 to 30 ads.

## `activeStatus` (type: `string`):

active: ads running now (the Ad Library's default). inactive: stopped ads. all: both.

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

Only ads with this media: all, image, video, meme, image_and_meme or none.

## `exactPhrase` (type: `boolean`):

On: keywords must appear as written, words together and in order. Off: words anywhere in the ad.

## `startedAfter` (type: `string`):

Only ads that started running on or after this date, YYYY-MM-DD. Example: 2026-10-01.

## `startedBefore` (type: `string`):

Only ads that started running on or before this date, YYYY-MM-DD. Example: 2026-10-14.

## `minDaysRunning` (type: `integer`):

Only ads running at least this many days, for example 30 for proven ads. Shorter ads are skipped and not charged. 0: no minimum.

## `maxDaysRunning` (type: `integer`):

Only ads running at most this many days, for example 7 for new ads. Longer ads are skipped and not charged. 0: no maximum.

## `dedupe` (type: `string`):

ad (default): an ad found by several searches is returned and charged once, for the first search. creative: also one row for ads with the same advertiser, text, headline and link under different IDs. none: every search returns all its ads.

## `excludeAdIds` (type: `array`):

Ad Library IDs you already have (ad_archive_id). They are skipped and not charged. Example: 850871490946466.

## Actor input object example

```json
{
  "queries": [
    "running shoes"
  ],
  "country": "US",
  "maxAds": 30,
  "activeStatus": "active",
  "mediaType": "all",
  "exactPhrase": false,
  "minDaysRunning": 0,
  "maxDaysRunning": 0,
  "dedupe": "ad"
}
```

# Actor output Schema

## `results` (type: `string`):

Every row: ads (status ok) and free error rows (status error).

## `summary` (type: `string`):

Counts by status and error_code.

# 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 = {
    "queries": [
        "running shoes"
    ],
    "country": "US",
    "maxAds": 30
};

// Run the Actor and wait for it to finish
const run = await client.actor("data-for-agents/facebook-ads-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 = {
    "queries": ["running shoes"],
    "country": "US",
    "maxAds": 30,
}

# Run the Actor and wait for it to finish
run = client.actor("data-for-agents/facebook-ads-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 '{
  "queries": [
    "running shoes"
  ],
  "country": "US",
  "maxAds": 30
}' |
apify call data-for-agents/facebook-ads-library-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,data-for-agents/facebook-ads-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/bFRy0BBZPtaaHSk8S/builds/EtmT7aoZkRdAlcF4z/openapi.json
