# Facebook Ad Library Scraper (`bgfc97/facebook-ad-library-scraper`) Actor

Scrape the public Facebook Ad Library by keyword or page: advertiser, ad copy, media, CTA, start date and platforms. No login required.

- **URL**: https://apify.com/bgfc97/facebook-ad-library-scraper.md
- **Developed by:** [Bruno](https://apify.com/bgfc97) (community)
- **Categories:** Marketing, Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$3.00 / 1,000 ad scrapeds

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 Ad Library Scraper (no login)

Scrape the **public** [Facebook Ad Library](https://www.facebook.com/ads/library/) with a real
headless browser (Playwright) behind an Apify **residential** proxy — **no login, no account, no
cookies, no email or password**. The Ad Library is Meta's public ad-transparency tool, so its
results are served to logged-out visitors.

### What it does

Search the library by **advertiser name / keyword** *or* by **Facebook Page ID**, choose a
**country** and **ad type**, and get back the ads currently in the library. Instead of fragile DOM
scraping, the actor intercepts the Ad Library's own **public GraphQL `search_ads` responses** (the
exact data the public site renders) and scrolls to paginate until it has enough ads.

### Input

| Field | Description |
|-------|-------------|
| `searchTerms` | Advertiser names / keywords, e.g. `["Nike","black friday"]` |
| `pageIds` | Numeric Facebook Page IDs to pull one advertiser's ads, e.g. `["15087023444"]` |
| `country` | ISO country code (`US`, `BR`, `GB`, `DE`, …) or `ALL`. Default `US` |
| `adType` | `all` (default) or `political` (political & issue ads, with spend/impression ranges) |
| `activeStatus` | `active` (default), `inactive`, or `all` |
| `maxItems` | Max ads to collect in total across all targets (default 30) |
| `proxyConfiguration` | Residential proxy (default & recommended) |
| `timeoutSecs` | Per-navigation timeout, 20–180 (default 60) |

At least one of `searchTerms` or `pageIds` is required.

### Output (per ad)

`ad_archive_id`, `ad_library_url`, `is_active`, `advertiser` (page id / name / url / profile
picture), `ad_copy` (body / title / caption / link description), `cta` (text / type /
destination\_url), `media` (image URLs, video URLs + preview, carousel cards, display format),
`start_date`, `end_date`, `publisher_platforms` (Facebook / Instagram / Messenger / Audience
Network), and `political` transparency fields (currency / spend / impressions / byline) for
political & issue ads.

### Notes

- **No login, ever.** The Ad Library is public; the actor never authenticates.
- A **residential** proxy is strongly recommended — datacenter IPs get blocked or return empty.
- It never fabricates ads: if a query returns none, it reports `adsFound: 0` honestly.

# Actor input Schema

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

List of advertiser names or keywords to search the Facebook Ad Library for, e.g. "Nike", "Coca-Cola", "black friday". Each term is searched separately (keyword\_unordered). Leave empty if you instead search by Page ID below. At least one of Search terms or Page IDs is required.

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

List of numeric Facebook Page IDs to pull all of a specific advertiser's library ads (view\_all\_page\_id). Use this when you already know the Page ID (e.g. "15087023444"). You can find a Page ID from the Ad Library URL of an advertiser. Leave empty if you search by term above.

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

Two-letter ISO country code the Ad Library filters ads by, e.g. "US", "BR", "GB", "DE", or "ALL" for all countries. The Ad Library always requires a country context; US is a safe default with the most inventory.

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

Which slice of the library to search. "all" = all ads currently running across Facebook's apps. "political" = only political & issue ads (these expose extra data such as spend and impression ranges).

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

Filter by whether the ad is currently running. "active" = only ads active right now (default), "inactive" = only stopped ads still archived, "all" = both active and inactive library ads.

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

Maximum number of ads to collect in total across every search term / Page ID in this run. The scraper scrolls the results to load more until this cap is reached or the library has no more matches. Returns fewer (or zero) honestly rather than padding with fake data.

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

Facebook aggressively blocks datacenter IPs and unauthenticated traffic. A RESIDENTIAL proxy group is strongly recommended and used by default — without it, the Ad Library GraphQL requests are very likely blocked or return empty.

## `timeoutSecs` (type: `integer`):

Timeout for each Ad Library page navigation in the real headless browser. Between 20 and 180 seconds.

## Actor input object example

```json
{
  "searchTerms": [
    "Nike"
  ],
  "pageIds": [],
  "country": "US",
  "adType": "all",
  "activeStatus": "active",
  "maxItems": 30,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  },
  "timeoutSecs": 60
}
```

# Actor output Schema

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

Real headless-browser (Playwright) scraper for the PUBLIC Facebook Ad Library (facebook.com/ads/library) — NO login ever (no account, cookies, email or password). Search by advertiser name / keyword OR by a Facebook Page ID, choose a country (US, BR, GB, ALL, ...) and ad type (all or political & issue), and get the ads currently in the library: ad archive id, advertiser (Page name + id), ad copy (body / title / caption / link description), media (image and video URLs), start date (and end date when present), publisher platforms (Facebook / Instagram / Messenger / Audience Network), the ad's own Ad Library link, and the CTA text + destination URL when visible. Works by intercepting the Ad Library's own public GraphQL search\_ads responses (the same data the public site shows) behind an Apify RESIDENTIAL proxy. Never fabricates ads and reports honestly when a query returns none.

# 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"
    ],
    "pageIds": [],
    "country": "US",
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("bgfc97/facebook-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"],
    "pageIds": [],
    "country": "US",
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    },
}

# Run the Actor and wait for it to finish
run = client.actor("bgfc97/facebook-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"
  ],
  "pageIds": [],
  "country": "US",
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call bgfc97/facebook-ad-library-scraper --silent --output-dataset

```

## MCP server setup

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