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

Search the Meta Ad Library by keyword, advertiser page or pasted link, any country, active or past ads. Each ad comes back as one row with archive ID, advertiser, dates, platforms, ad text, headline, link, call to action, format and media links.

- **URL**: https://apify.com/barefoot_grade/facebook-ads-library-scraper.md
- **Developed by:** [Philip Kirkbride](https://apify.com/barefoot_grade) (community)
- **Categories:** Social media, Lead generation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.50 / 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

## Facebook Ads Library Scraper

Search the Meta Ad Library (facebook.com/ads/library) the way you do on the site: type a keyword, open an advertiser's page of ads, or paste a search link you already filtered. Every ad comes back as one clean row with its Ads Library ID and link, the advertiser's name, page and like count, the dates it started and stopped running, the platforms it runs on (Facebook, Instagram, Messenger, Audience Network, Threads, WhatsApp), the ad text, headline, link, call to action and format, plus links to its images, videos and carousel cards.

Results page through automatically up to your limit, so one search can return hundreds of ads instead of the first screen. No Facebook account is needed.

### Use cases

- **Competitor ad research**: list every ad a competitor is running right now, with the text, offer, landing page and call to action they test.
- **Creative inspiration**: collect ads for a keyword or niche and study the hooks, formats and media that keep running for months.
- **Market and trend monitoring**: re-run the same searches on a schedule and see which advertisers start, stop or scale campaigns.
- **Lead generation**: find businesses that advertise in your market, with their page links and landing pages.
- **Political and issue ad tracking**: collect ads with their paid-for-by line, and spend and impression ranges where the Ads Library publishes them.

### Quick Start

```json
{
  "searchTerms": ["running shoes"],
  "country": "US",
  "activeStatus": "active",
  "maxItemsPerSearch": 50
}
```

Every ad of one advertiser, in every country, running or stopped:

```json
{
  "pageIds": ["15087023444"],
  "country": "ALL",
  "activeStatus": "all",
  "maxItemsPerSearch": 200
}
```

### Input

| Input | Type | Default | Meaning |
| --- | --- | --- | --- |
| `searchTerms` | array | `[]` | Keywords to search ad text for, as you would type them in the Ads Library search box. Each term is one search. |
| `pageIds` | array | `[]` | Numeric advertiser page IDs. Each one lists that advertiser's ads. You find the ID in an Ads Library link after `view_all_page_id=`. |
| `adLibraryUrls` | array | `[]` | Search or advertiser links copied from facebook.com/ads/library. The country, ad status and media type inside each link are used for that link. |
| `country` | string | `US` | Two-letter country code where the ads were shown (`US`, `GB`, `DE`, `BR`...), or `ALL` for every country. |
| `activeStatus` | string | `active` | `active` (running now), `inactive` (stopped) or `all`. |
| `mediaType` | string | `all` | `all`, `image`, `video`, `meme`, `image_and_meme` or `none` (ads without an image or video). |
| `maxItems` | integer | empty | Optional total ad limit across all searches; empty means no extra run-wide limit. |
| `maxItemsPerSearch` | integer | `100` | Stop each search after this many ads, up to 5,000. |

You can mix search terms, page IDs and links in one run. Ads already returned by an earlier search in the same run are not repeated.

### Example queries

- `{"searchTerms": ["meal kit", "protein powder"], "maxItemsPerSearch": 300}`: up to 300 running US ads for each keyword.
- `{"searchTerms": ["solar panels"], "country": "GB", "mediaType": "video"}`: video ads about solar panels shown in the UK.
- `{"pageIds": ["15087023444"], "activeStatus": "all", "country": "ALL"}`: the advertiser's full ad history across countries.
- `{"adLibraryUrls": ["https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=DE&q=versicherung&search_type=keyword_unordered&media_type=all"]}`: a search you set up on the site, pasted as is.

### What it returns

The dataset contains one row per ad:

| Field | Meaning |
| --- | --- |
| `kind` | `ad` for every dataset row. |
| `adArchiveId`, `adLibraryUrl` | The Ads Library ID of the ad and its link in the Ads Library. |
| `pageId`, `pageName`, `pageProfileUrl`, `pageProfilePictureUrl` | The advertiser's page. |
| `pageLikeCount`, `pageCategories` | Page likes and categories, as shown with the ad. |
| `isActive`, `startDate`, `endDate` | Whether the ad is running, the date it started and the date it stopped (or the latest date it was seen running), `YYYY-MM-DD`. |
| `publisherPlatforms` | Where it runs: `facebook`, `instagram`, `messenger`, `audience_network`, `threads`, `whatsapp`. |
| `displayFormat` | `IMAGE`, `VIDEO`, `CAROUSEL`, `DCO` (dynamic creative), `DPA` (product catalog) and so on. |
| `body`, `title`, `linkDescription`, `caption` | The ad text, headline, link description and the domain shown on the ad. |
| `linkUrl`, `ctaText`, `ctaType` | Where the ad leads and its call-to-action button. |
| `images` | Image links, each with `originalUrl` and `resizedUrl`. |
| `videos` | Video links, each with `hdUrl`, `sdUrl` and `previewImageUrl`. |
| `cards` | Carousel and catalog cards, each with its own `title`, `body`, `linkUrl`, `linkDescription`, `caption`, `ctaText`, `ctaType` and image or video links. |
| `collationId`, `collationCount` | Shared ID and count when several ads use the same creative. |
| `categories` | Special ad categories (for example `POLITICAL`, `HOUSING`) when declared. |
| `containsSensitiveContent` | Whether the Ads Library marks the ad as sensitive. |
| `spend`, `currency`, `impressions`, `reachEstimate` | Ranges published for political and issue ads; empty for other ads. |
| `disclaimer` | The paid-for-by line, when the ad carries one. |
| `searchTerm`, `searchPageId`, `searchCountry`, `searchUrl` | The search this row came from. |
| `scrapedAt` | Collection time (UTC). |

The run summary (`OUTPUT`) lists each search with the number of ads and pages returned, whether it reached the end or your limit, and any error. Searches that failed or stopped early are listed in `OUTPUT.searchErrors` with the number of ads they delivered before stopping. After three searches in a row are refused or slowed down without returning ads, or when the run cannot renew access, it stops. `OUTPUT.stoppedBy` records why; `OUTPUT.skippedSearches` lists searches not attempted, which are not charged.

### Output example

```json
{
  "kind": "ad",
  "adArchiveId": "1702938977100376",
  "adLibraryUrl": "https://www.facebook.com/ads/library/?id=1702938977100376",
  "pageId": "15087023444",
  "pageName": "Nike",
  "pageProfileUrl": "https://www.facebook.com/nike/",
  "pageProfilePictureUrl": "https://scontent-phl2-1.xx.fbcdn.net/v/t39.35426-6/431756959_712871054375981_n.jpg",
  "pageLikeCount": 39500444,
  "pageCategories": ["Sportswear", "Product/service"],
  "isActive": true,
  "startDate": "2025-04-07",
  "endDate": "2026-10-19",
  "publisherPlatforms": ["facebook", "instagram", "audience_network", "messenger"],
  "displayFormat": "DPA",
  "body": "Bring sports more fully into your day with the Nike App.",
  "title": "{{product.name}}",
  "linkUrl": "http://itunes.apple.com/app/id1095459556",
  "linkDescription": null,
  "caption": "itunes.apple.com",
  "ctaText": "Install now",
  "ctaType": "INSTALL_MOBILE_APP",
  "images": [],
  "videos": [],
  "cards": [
    {
      "title": "Nike Run Swift 3 Women's Road Running Shoes",
      "body": "Bring sports more fully into your day with the Nike App.",
      "linkUrl": "https://www.nike.com/ph/t/run-swift-3-road-running-shoes-2fHbzp/DR2698-002",
      "linkDescription": "₱3,995",
      "caption": "itunes.apple.com",
      "ctaText": "Install Now",
      "ctaType": "INSTALL_MOBILE_APP",
      "originalImageUrl": "https://scontent-phl2-1.xx.fbcdn.net/v/t39.35426-6/431679131_949214166636263_n.jpg",
      "resizedImageUrl": "https://scontent-phl2-1.xx.fbcdn.net/v/t39.35426-6/431679131_949214166636263_s600x600.jpg",
      "videoHdUrl": null,
      "videoSdUrl": null,
      "videoPreviewImageUrl": null
    }
  ],
  "collationId": null,
  "collationCount": null,
  "categories": [],
  "containsSensitiveContent": false,
  "spend": null,
  "currency": null,
  "impressions": null,
  "reachEstimate": null,
  "disclaimer": null,
  "searchTerm": null,
  "searchPageId": "15087023444",
  "searchCountry": "ALL",
  "searchUrl": "https://www.facebook.com/ads/library/?active_status=all&ad_type=all&country=ALL&media_type=all&search_type=page&view_all_page_id=15087023444",
  "scrapedAt": "2026-10-20T05:41:00+00:00"
}
```

Image and video links are shortened here; real links are longer and expire after some days, so download media you want to keep soon after the run.

### Good to know

- Results come in the Ads Library's own order. Keyword searches match ad text, so broad words return many advertisers.
- `title` and `body` of catalog ads (`DPA`) can hold placeholders such as `{{product.name}}`; the real product names are in `cards`.
- Spend, impressions and reach are only published by the Ads Library for political and issue ads (and some regulated regions); they are empty otherwise.
- Ads already returned by an earlier search in the same run are skipped, so overlapping searches do not return duplicates.
- If a search stops early, the ads it already returned are kept and the reason is shown in the run summary. If no search returns any ad because of an error, the run fails with a clear message instead of finishing empty. A search with no matching ads is reported in the run summary as no results and is not charged.
- `maxItemsPerSearch` goes up to 5,000 ads per search. Large searches take a few minutes per thousand ads.
- Automated access is subject to Meta's terms; use this actor only where you have the necessary permissions and a lawful basis.

### Pricing

You pay per ad returned plus a small start event for each run. The start event is charged per GB of memory, so the default 4096 MB run is four start events. See the Actor's Pricing tab on Apify for current rates. Searches that fail are not charged, and the run summary is free. Start with a small `maxItemsPerSearch` and check the run cost before scheduling larger collections.

# Actor input Schema

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

Keywords to search ad text for, as you would type them in the Ads Library search box. Each term is one search.

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

Numeric Facebook page IDs to list every ad of that advertiser (the number after view_all_page_id= in an Ads Library link). Each page is one search.

## `adLibraryUrls` (type: `array`):

Search or advertiser links copied from facebook.com/ads/library. The filters inside each link (country, active status, media type) are used for that link.

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

Two-letter country code where the ads were shown (US, GB, DE, BR...), or ALL for every country.

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

Only ads running now, only ads that have stopped, or both.

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

Limit results to ads with this kind of media.

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

Optional total ad limit across all searches. Leave empty for no extra run-wide limit. Rows beyond this limit are not charged.

## `maxItemsPerSearch` (type: `integer`):

Stop each search after this many ads. Ads already returned by an earlier search in the same run are not repeated.

## Actor input object example

```json
{
  "searchTerms": [
    "running shoes"
  ],
  "pageIds": [],
  "adLibraryUrls": [],
  "country": "US",
  "activeStatus": "active",
  "mediaType": "all",
  "maxItemsPerSearch": 50
}
```

# Actor output Schema

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

No description

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

No description

# 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": [
        "running shoes"
    ],
    "pageIds": [],
    "adLibraryUrls": [],
    "country": "US",
    "activeStatus": "active",
    "mediaType": "all",
    "maxItemsPerSearch": 50
};

// Run the Actor and wait for it to finish
const run = await client.actor("barefoot_grade/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 = {
    "searchTerms": ["running shoes"],
    "pageIds": [],
    "adLibraryUrls": [],
    "country": "US",
    "activeStatus": "active",
    "mediaType": "all",
    "maxItemsPerSearch": 50,
}

# Run the Actor and wait for it to finish
run = client.actor("barefoot_grade/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 '{
  "searchTerms": [
    "running shoes"
  ],
  "pageIds": [],
  "adLibraryUrls": [],
  "country": "US",
  "activeStatus": "active",
  "mediaType": "all",
  "maxItemsPerSearch": 50
}' |
apify call barefoot_grade/facebook-ads-library-scraper --silent --output-dataset

```

## MCP server setup

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