# Facebook Ads Library Scraper (`datascrapers/facebook-ads-scraper`) Actor

Collect Facebook Ads Library ads by URL, keyword, or advertiser page ID, including creative copy, platforms, status, and optional advertiser details.

- **URL**: https://apify.com/datascrapers/facebook-ads-scraper.md
- **Developed by:** [Farhan Ali](https://apify.com/datascrapers) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

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

**Facebook Ads Library Scraper** creates a structured dataset of ads collected from the [Facebook Ads Library](https://www.facebook.com/ads/library). Each dataset item represents one ad (or one advertiser in unique-advertiser mode) and can include page name, copy, creative format, platforms, dates, impressions text, destination URL, and optional advertiser-detail fields. Query the source with Ads Library URLs (`startUrls`), keywords (`searchQueries`), or advertiser page IDs (`pageIds`). Control the result limit with `maxItems`, and retrieve records through the Apify Dataset API or export them as JSON, CSV, Excel, XML, or another supported format.

### Dataset at a glance

| Property | Value |
|---|---|
| Source | facebook.com/ads/library |
| Record unit | One ad, or one advertiser when unique-advertiser mode is on |
| Input methods | Ads Library URLs (`startUrls`), keywords (`searchQueries`), and/or page IDs (`pageIds`) |
| Main identifiers | `ad_archive_id`, Ads Library URL (`ads_library_url`) |
| Delivery | Apify Dataset and API |
| Export formats | JSON, CSV, Excel, XML, HTML (Apify dataset exports) |
| Update model | Fresh records per Actor run |
| Pricing | $1.70 / 1,000 ads; +$1.50 / 1,000 ad details; unique-advertiser mode $1.70 / 1,000 ads scraped; Actor start $0.00005 |

### Coverage and available records

The Actor collects public Ads Library records. Provide at least one URL, search query, or page ID.

- **URL-based**: `startUrls` accepts Ads Library search URLs. Filters encoded in the URL are used as-is.
- **Keyword-based**: `searchQueries` (for example `Nike`) with `searchType` `keyword_unordered` (default), `keyword_exact`, or `page`.
- **Advertiser-based**: `pageIds` scopes results to those Facebook page IDs.

Filters (used when you are not relying only on a pasted URL): `country` (default `US`, or `ALL`), `category` (`all`, `political`, `housing`, `employment`, `financial`), `activeStatus` (`all`, `active`, `inactive`), `mediaType` (`all`, `image`, `meme`, `video`), `publisherPlatforms` (`facebook`, `instagram`, `messenger`, `audience_network`, `threads`), `sortBy` (`most_recent`, `impressions`), `startDate` / `endDate`, `impressionWindow` (`any`, `last_7_days`, `last_30_days`, `last_90_days`), and `isTargetedCountry`.

Record types and limits:

- **Ad records** are collected in the default mode: page, copy, format, platforms, dates, and Ads Library permalink.
- **Ad details** are conditional: advertiser profile, Instagram, spend, transparency, and creative variants are returned when `includeAdDetails` is enabled (default `false`) and charged as `ad-details`.
- **Unique-advertiser mode**: `uniqueAdvertisersOnly` writes one row per company. Charging uses `filter-run` once per ad scraped, including ads collapsed as repeats (for example 100 ads from 70 companies writes 70 rows and charges 100 unique-ad events).
- **Result cap**: `maxItems` limits ads or unique advertisers (`0` means unlimited; console prefill `50`).

Known exclusions: content not shown in the public Ads Library is not collected; each run captures Library state at run time (no historical snapshots).

### Data dictionary

Field names below match dataset record JSON properties exactly. Additional media and detail fields may appear when the Library returns them.

| Field | Type | Nullable | Description | Example |
|---|---|---:|---|---|
| `record_type` | string | Yes | Record kind | `ad` |
| `ad_archive_id` | string | No | Ads Library archive identifier; recommended deduplication key | `2071991237016362` |
| `page_name` | string | Yes | Advertiser page name | `Acervo Inmobiliario` |
| `page_id` | string | Yes | Advertiser page ID | `639331409798946` |
| `body_text` | string | Yes | Primary ad copy | `Acervo llega a New York...` |
| `title` | string | Yes | Ad title | `Invierte en RD desde New York` |
| `cta_text` | string | Yes | Call-to-action text | `Sign up` |
| `display_format` | string | Yes | Creative format | `IMAGE` |
| `is_active` | boolean | Yes | Whether the ad is marked active | `true` |
| `start_date` | string | Yes | Start date as returned | `2026-08-31` |
| `publisher_platforms` | string\[] | Yes | Platforms where the ad ran | `["FACEBOOK", "INSTAGRAM"]` |
| `impressions` | string | Yes | Impressions text as shown | `<100` |
| `link_url` | string | Yes | Destination URL when listed | `https://facebook.com/marketplace/item/...` |
| `ads_library_url` | string | Yes | Ads Library permalink | `https://www.facebook.com/ads/library/?id=2071991237016362` |
| `page_like_count` | number | Yes | Page like count when shown | `38` |

Detail-mode runs can add advertiser about, Instagram, spend, transparency, and creative-variant fields when `includeAdDetails` is enabled.

### Example dataset record

Ad from a keyword search. Detail fields are absent because `includeAdDetails` was off.

```json
{
  "record_type": "ad",
  "ad_archive_id": "2895769867482327",
  "page_name": "Alli Hanson",
  "page_id": "101900028661031",
  "body_text": "Nike Ja 3 Kool-Aid men’s size 9 - $85.00",
  "title": "Nike Ja 3 Kool-Aid men’s size 9",
  "cta_text": "Contact us",
  "display_format": "IMAGE",
  "is_active": true,
  "start_date": "2026-08-31",
  "publisher_platforms": ["FACEBOOK", "INSTAGRAM"],
  "impressions": "<100",
  "link_url": "https://facebook.com/marketplace/item/1046035275085979/",
  "ads_library_url": "https://www.facebook.com/ads/library/?id=2895769867482327"
}
```

The record above was produced with this input:

```json
{
  "searchQueries": ["Nike"],
  "country": "US",
  "maxItems": 50,
  "includeAdDetails": false
}
```

### Query and input reference

| Input | Type | Required | Default | Accepted values | Description |
|---|---|---:|---|---|---|
| `startUrls` | array (requestListSources) | No\* | — | Facebook Ads Library URLs | URL filters are used as-is |
| `searchQueries` | array (string) | No\* | — (prefill `Nike`) | Keywords | Each query is a separate search |
| `searchType` | string | No | `keyword_unordered` | `keyword_unordered`, `keyword_exact`, `page` | Keyword match mode |
| `pageIds` | array (string) | No\* | — | Facebook page IDs | Advertiser scope |
| `country` | string | No | `US` | Ads Library country codes or `ALL` | Country dropdown |
| `category` | string | No | `all` | `all`, `political`, `housing`, `employment`, `financial` | Library category |
| `activeStatus` | string | No | `all` | `all`, `active`, `inactive` | Ad status |
| `mediaType` | string | No | `all` | `all`, `image`, `meme`, `video` | Media filter |
| `publisherPlatforms` | array (string) | No | — | `facebook`, `instagram`, `messenger`, `audience_network`, `threads` | Empty = all platforms |
| `sortBy` | string | No | `most_recent` | `most_recent`, `impressions` | Sort order |
| `startDate` | string | No | — | Date | Impressions from |
| `endDate` | string | No | — | Date | Impressions until |
| `impressionWindow` | string | No | `any` | `any`, `last_7_days`, `last_30_days`, `last_90_days` | Audience window |
| `isTargetedCountry` | boolean | No | `false` | `true` / `false` | Targeted-country flag |
| `includeAdDetails` | boolean | No | `false` | `true` / `false` | Attach detail fields (charged as ad details) |
| `detailsConcurrency` | integer | No | `8` | `1`–`20` | Parallel detail requests |
| `uniqueAdvertisersOnly` | boolean | No | `false` | `true` / `false` | One row per company; charged per ad scraped |
| `maxItems` | integer | No | `0` | `0` or any positive integer | Cap; `0` = unlimited (console prefill `50`) |
| `proxyConfiguration` | object | No | Apify proxy, `RESIDENTIAL` | Apify proxy groups or custom proxies | Residential proxies are recommended |

\* Provide `startUrls`, `searchQueries`, and/or `pageIds`.

Minimal request:

```json
{ "searchQueries": ["Nike"], "country": "US" }
```

Advanced request (URL + details):

```json
{
  "startUrls": [{ "url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&q=Nike&search_type=keyword_unordered" }],
  "includeAdDetails": true,
  "maxItems": 50
}
```

### Retrieve the data through the API

Records are delivered through the Apify Actor and Dataset APIs — not an official Meta API.

1. Start the Actor with a JSON input (console or API).
2. Wait for the run to finish, or use a synchronous endpoint if you want the response inline.
3. Retrieve items from the run's default dataset.
4. Paginate or export the dataset.

Python example:

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR-APIFY-TOKEN")

run_input = {
    "searchQueries": ["Nike"],
    "country": "US",
    "maxItems": 20,
}

run = client.actor("datascrapers/facebook-ads-scraper").call(run_input=run_input)
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item.get("ad_archive_id"), item.get("page_name"), item.get("title"))
```

Apify generates ready-to-run Python, JavaScript, and cURL examples on the Actor's [API tab](https://apify.com/datascrapers/facebook-ads-scraper/api). Do not put a real API token in shared code or URLs.

### Data quality and record handling

- **Conditional fields**: detail fields exist only when `includeAdDetails` is enabled.
- **Unique-advertiser charging**: `filter-run` is charged per ad scraped, not per company row written.
- **Source changes**: Ads Library fields can change; unreadable values are omitted rather than fabricated.
- **Deduplication**: within a run, ads are identified by `ad_archive_id`. Across runs, records are appended.
- **Normalization**: dates and impressions text are stored as the Library shows them.

### Export and pipeline examples

| Destination | Recommended method | Typical use |
|---|---|---|
| PostgreSQL / Supabase | Dataset API poll or webhook consumer | Store creative archives |
| Google Sheets | Apify Google Sheets integration | Share competitor shortlists |
| BI / reporting | Dataset API JSON export | Creative and platform mix |
| S3 / cloud storage | Scheduled export via Apify scheduler + integration | Archival of Library snapshots |

### Pricing and cost examples

The Actor uses pay-per-event pricing. Each run also charges a one-time Actor start. Residential proxies are recommended. Proxy and compute are billed by your Apify plan. Event charges may be tiered on Apify paid plans.

| Event | Trigger | Rate |
|---|---|---|
| Actor start | Once per run | $0.00005 |
| `dataset-item` (Ad) | Each ad in a normal run | $0.0017 / ad ($1.70 / 1,000) |
| `ad-details` (Ad Details) | Each ad opened with details | $0.0015 / ad ($1.50 / 1,000) |
| `filter-run` (Unique Ads) | Each ad scraped in unique-advertiser mode | $0.0017 / ad scraped ($1.70 / 1,000) |

Example costs (Actor start negligible; plan-tier discounts not applied):

| Records | Configuration | Estimated base cost |
|---:|---|---:|
| 1,000 | Ads only | $1.70 |
| 1,000 | Ads + details | $3.20 |

Estimates depend on the verified pricing model and the options selected for the run.

### Limitations and responsible data use

- The Actor collects publicly accessible Facebook Ads Library records only.
- Field availability depends on what the Library renders at run time; spend and reach can be missing.
- The Actor does not provide historical snapshots unless you store them yourself.
- Large runs should use residential proxies; without them, coverage may degrade.
- You are responsible for compliance with Meta's terms of service, applicable privacy law, and any contractual obligations before using the data.

### Dataset questions

#### What does one dataset item represent?

One ad in the default mode. In unique-advertiser mode, one company, after collapsing repeat ads.

#### Which field should I use as a unique identifier?

`ad_archive_id` for ads. `page_id` for advertiser-level rows. `ads_library_url` is a reasonable secondary key.

#### Are fields nullable or conditional?

Yes. Detail fields exist only when `includeAdDetails` is enabled. Impressions, destination URL, and like count can be missing.

#### Can I retrieve the records as CSV or JSON?

Yes. The dataset can be exported as JSON, CSV, Excel, XML, or HTML from the Apify Console, and queried through the Dataset API.

#### Does the Actor return historical data?

No. Each run captures Library state at run time. To track new creatives, schedule repeated runs and store the outputs yourself.

#### What counts as a billable result?

Actor start once per run ($0.00005). A normal run charges `dataset-item` per ad ($0.0017). Details add `ad-details` ($0.0015). Unique-advertiser mode charges `filter-run` per ad scraped ($0.0017), including collapsed repeats.

### Related datasets from Data Scrapers

- **[Facebook Marketplace Scraper](https://apify.com/datascrapers/facebook-marketplace)** — Marketplace listings that often appear as Ads Library destinations.
- **[Instagram Post Scraper](https://apify.com/datascrapers/instagram-post-scraper)** — Organic Instagram posts for the same advertiser pages.
- **[Instagram Comment Scraper](https://apify.com/datascrapers/instagram-comment-scraper)** — Comments on creatives that overlap Ads Library campaigns.
- **[TikTok Profile Scraper](https://apify.com/datascrapers/tiktok-profile-scraper)** — Cross-platform advertiser presence.
- **[Yelp Scraper](https://apify.com/datascrapers/yelp-scraper)** — Local-business records that can be joined to advertiser page names.

### Data Scrapers support

Need an additional field, record type, or export workflow? Contact Data Scrapers at stardustspotlight@gmail.com. Include a sample source URL, required fields, expected record volume, and preferred delivery format.

# Actor input Schema

## `startUrls` (type: `array`):

Paste one or more Facebook Ads Library search URLs (e.g. https://www.facebook.com/ads/library/?q=Nike\&country=US). Filters encoded in the URL are used as-is. Leave empty to search with the filter fields below.

## `searchQueries` (type: `array`):

Keywords to search in Ads Library (e.g. Nike, insurance, crypto). Used when you are not pasting a full Ads Library URL. Each query is a separate search.

## `searchType` (type: `string`):

How keywords are matched. Page search is used automatically when advertiser page IDs are provided.

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

Optional Facebook page IDs to scrape ads for a specific advertiser (same as view\_all\_page\_id in Ads Library).

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

Country shown in the Ads Library country dropdown.

## `category` (type: `string`):

Ads Library category: all ads, issues/elections/politics, properties (housing), employment, or financial products and services.

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

Active ads, inactive ads, or both.

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

Restrict results to images, images and memes, or videos.

## `publisherPlatforms` (type: `array`):

Where the ad ran. Leave empty for all platforms.

## `sortBy` (type: `string`):

Most recent (Ads Library default grouping) or impressions high to low.

## `startDate` (type: `string`):

Only include ads that started running on or after this date.

## `endDate` (type: `string`):

Only include ads that started running on or before this date.

## `impressionWindow` (type: `string`):

Optional Ads Library audience window (ads seen in the last 7 / 30 / 90 days).

## `isTargetedCountry` (type: `boolean`):

Match Ads Library's is\_targeted\_country flag.

## `includeAdDetails` (type: `boolean`):

Open each ad's detail pane (advertiser profile, Instagram, spend, transparency, creative variants). Charged as a separate ad-details event. Requests run concurrently and each uses a rotated proxy.

## `detailsConcurrency` (type: `integer`):

How many ad-detail requests to run at once. Each request opens a new session with a rotated proxy. Only used when Include ad details is on.

## `uniqueAdvertisersOnly` (type: `boolean`):

Return one row per company instead of every ad. Charged as Unique Ads (filter-run) once per ad scraped, including ads collapsed as repeats. Example: 100 ads from 70 companies writes 70 rows and charges 100 filter-run events.

## `maxItems` (type: `integer`):

Maximum ads (or unique advertisers) to scrape. 0 = unlimited.

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

Apify Residential proxies are recommended for Ads Library.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&is_targeted_country=false&media_type=all&q=Nike&search_type=keyword_unordered"
    }
  ],
  "searchQueries": [
    "Nike"
  ],
  "searchType": "keyword_unordered",
  "country": "US",
  "category": "all",
  "activeStatus": "all",
  "mediaType": "all",
  "sortBy": "most_recent",
  "impressionWindow": "any",
  "isTargetedCountry": false,
  "includeAdDetails": false,
  "detailsConcurrency": 8,
  "uniqueAdvertisersOnly": false,
  "maxItems": 50,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

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

Dataset containing scraped ads or unique advertisers

## `runStats` (type: `string`):

Record counts and timestamps for 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 = {
    "startUrls": [
        {
            "url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&is_targeted_country=false&media_type=all&q=Nike&search_type=keyword_unordered"
        }
    ],
    "searchQueries": [
        "Nike"
    ],
    "maxItems": 50,
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("datascrapers/facebook-ads-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 = {
    "startUrls": [{ "url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&is_targeted_country=false&media_type=all&q=Nike&search_type=keyword_unordered" }],
    "searchQueries": ["Nike"],
    "maxItems": 50,
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    },
}

# Run the Actor and wait for it to finish
run = client.actor("datascrapers/facebook-ads-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 '{
  "startUrls": [
    {
      "url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&is_targeted_country=false&media_type=all&q=Nike&search_type=keyword_unordered"
    }
  ],
  "searchQueries": [
    "Nike"
  ],
  "maxItems": 50,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call datascrapers/facebook-ads-scraper --silent --output-dataset

```

## MCP server setup

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