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

Collect Meta Ad Library ads by keyword or advertiser as flat, analysis-ready JSON. No login, no browser, no Graph API token.

- **URL**: https://apify.com/seasonedsalt23/facebook-ads-library-scraper.md
- **Developed by:** [ray](https://apify.com/seasonedsalt23) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 1 monthly users, 77.8% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

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

## Meta Ad Library Scraper

Collect public Facebook and Instagram ads in Meta's Ad Library for a keyword or advertiser, as flat JSON ready for a spreadsheet, a database, or an LLM.

No Facebook login, no browser, no Graph API token. The actor reads the same public Ad Library the website serves.

### Why this one

- **Flat rows, not raw Meta JSON.** `adContent`, `adTitle`, `ctaText`, `landingPageUrl`, `imageUrls`, `videoUrls` and dates are top-level fields. The original record stays under `raw`.
- **One row per ad.** Duplicate ads across overlapping searches are merged, and every source that saw the ad is kept in `inputUrls`.
- **Date filters that hold.** Every returned `startDate` is checked against your cutoff, and pagination continues until enough qualifying ads are found.
- **Details and EU reach.** Turn on `includeDetails` for advertiser transparency and `eu_total_reach` where Meta publishes it.
- **Recovers instead of dying.** Bounded exponential backoff, `Retry-After`, session restart, and optional proxy rotation. A failed detail request keeps the base ad and records `detailsError`.
- **Honest partial runs.** If a source stops early, the run is marked partial and the manifest says which source and why.

### Input

Provide `searchQueries`, `startUrls`, or both.

If both source fields are omitted, the Actor uses `nike` as its default search. Explicitly empty source fields are rejected, so an intentionally cleared input does not silently run a different search.

```json
{
  "searchQueries": ["protein powder", "creatine"],
  "country": "US",
  "activeStatus": "active",
  "maxAdsPerSource": 200,
  "includeDetails": true
}
```

Search by advertiser with an Ad Library page URL:

```json
{
  "startUrls": [
    "https://www.facebook.com/ads/library/?country=US&active_status=active&ad_type=all&search_type=page&view_all_page_id=15087023444"
  ],
  "maxAdsPerSource": 100
}
```

| Field | Default | Notes |
| --- | --- | --- |
| `searchQueries` | | Keyword searches, one per line |
| `startUrls` | | Ad Library search URLs or Facebook page URLs |
| `country` | `US` | ISO country code for keyword searches |
| `activeStatus` | `active` | `active`, `all`, `inactive` |
| `mediaType` | `all` | `all`, `image`, `video`, `meme`, `none` |
| `maxAdsPerSource` | `100` | 1 to 5,000 per query or URL |
| `includeDetails` | `false` | One extra request per ad |
| `includeAboutPage` | `false` | One request per advertiser |
| `onlyAdsNewerThan` | | `YYYY-MM-DD` or `7 days` |
| `onlyAdsOlderThan` | | `YYYY-MM-DD` or `2 weeks` |
| `sorting` | `total_impressions` | Or `relevancy_monthly_grouped` |
| `maxPagesPerSource` | `0` | 0 means automatic |
| `maxRequests` | `0` | 0 means automatic |
| `maxRetries` | `4` | 0 to 10 |
| `backoffBaseSecs` | `2` | Doubles per attempt |
| `proxyConfiguration` | Apify Proxy | Residential recommended at volume |

### Output

One dataset item per ad. Key fields:

`adArchiveID`, `pageID`, `pageName`, `adContent`, `adTitle`, `displayFormat`, `startDate`, `startDateFormatted`, `endDateFormatted`, `isActive`, `publisherPlatform`, `ctaText`, `ctaType`, `landingPageUrl`, `imageUrls`, `videoUrls`, `inputUrls`, `detailsError`, `aboutError`, `raw`.

Empty searches are not charged as ads. They are stored in the `EMPTY_RESULTS` key-value record, with `MANIFEST` and `TOTALS` alongside. Advertiser details are under `ad_details` when `includeDetails` is on.

### Notes and limits

- The Ad Library is public. Meta's terms still restrict automated collection; use the data lawfully and do not republish creatives as your own.
- Spend and impressions are only available for political and issue ads. EU reach is only available for ads delivered in the EU.
- Media URLs are CDN links and expire. Mirror them if you need permanent assets.
- `maxAdsPerSource` is per query or URL. Ten queries at 200 can return up to 2,000 rows before deduplication.
- A partial run is not a failure. Read `MANIFEST` before assuming a source has no ads.
- The Actor sends the developer fixed error categories for incident monitoring. Alerts exclude input, ad data, run IDs, and logs.
- Apify's maximum-charge setting applies across all queries and URLs in a run. The Actor limits collection to the number of unique ads the remaining budget can cover, including optional details for those ads. If the budget truncates a search, `MANIFEST` reports `PARTIAL` with `spending_limit`; its billing summary records collected, written, and charged counts. No additional pages or sources are requested once that ad limit is reached.

### Pricing

$0.40 per 1,000 ads, pay per result. No start fee, and empty searches are free. Apify's free plan includes monthly credit for a first run.

# Actor input Schema

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

Keyword searches, one per line. Each query becomes its own Ad Library search.

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

Optional Ad Library search URLs or Facebook page URLs. Use these when you need filters the presets do not expose.

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

Two-letter ISO country code used for keyword searches.

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

Active ads only, inactive only, or both.

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

Filter keyword searches by creative format.

## `maxAdsPerSource` (type: `integer`):

Upper bound for each query or URL. Duplicate ads across sources are merged.

## `includeDetails` (type: `boolean`):

Fetch advertiser transparency and EU reach data. One extra request per ad.

## `includeAboutPage` (type: `boolean`):

Fetch page owner, history and admin locations. One request per advertiser.

## `onlyAdsNewerThan` (type: `string`):

YYYY-MM-DD or a relative value such as 7 days. Results are validated against the cutoff.

## `onlyAdsOlderThan` (type: `string`):

YYYY-MM-DD or a relative value such as 2 weeks.

## `sorting` (type: `string`):

Ad Library sort order.

## `maxPagesPerSource` (type: `integer`):

0 means automatic, scaled to the requested ad count.

## `maxRequests` (type: `integer`):

0 means automatic. A hard safety cap across the whole run.

## `maxRetries` (type: `integer`):

Retries per request for rate limits and transient failures.

## `backoffBaseSecs` (type: `integer`):

Exponential backoff base. The delay doubles per attempt and honours Retry-After.

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

Residential proxies are recommended above a few hundred ads.

## Actor input object example

```json
{
  "searchQueries": [
    "nike"
  ],
  "country": "US",
  "activeStatus": "active",
  "mediaType": "all",
  "maxAdsPerSource": 100,
  "includeDetails": false,
  "includeAboutPage": false,
  "sorting": "total_impressions",
  "maxPagesPerSource": 0,
  "maxRequests": 0,
  "maxRetries": 4,
  "backoffBaseSecs": 2,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `ads` (type: `string`):

One flat dataset row per unique ad, with creative copy, media URLs, advertiser metadata, and the original record under raw.

## `manifest` (type: `string`):

Collection status, unique ad counts, source failures, limits, and configured proxy count. A PARTIAL manifest means collection stopped early.

# 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 = {
    "searchQueries": [
        "nike"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("seasonedsalt23/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 = { "searchQueries": ["nike"] }

# Run the Actor and wait for it to finish
run = client.actor("seasonedsalt23/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 '{
  "searchQueries": [
    "nike"
  ]
}' |
apify call seasonedsalt23/facebook-ads-library-scraper --silent --output-dataset

```

## MCP server setup

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