# Facebook Ad Library Scraper - Verified Complete (`datanest-labs/facebook-ad-library-scraper`) Actor

Scrape Facebook & Instagram ads from the Meta Ad Library by keyword, page or URL. Get ad copy, headlines, CTAs, landing pages, images and videos. Every run checks its results against the Ad Library's own count, so ads are never silently missed. Fast, clean JSON/CSV export.

- **URL**: https://apify.com/datanest-labs/facebook-ad-library-scraper.md
- **Developed by:** [Ergin Bekar](https://apify.com/datanest-labs) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.50 / 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.
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 Ad Library Scraper: Complete Results, Verified Count

Scrape **every** ad from the Meta Ad Library (Facebook, Instagram, Messenger, Audience Network) by keyword, Page ID or Ad Library URL. You get the ad copy, headline, CTA, landing page URL, images, videos, platforms and run dates.

### Why this scraper?

The most common complaint about Ad Library scrapers is that **a run says it finished but only returns part of the ads**. This Actor fixes that:

- ✅ **Verified completeness:** each run reads the result count the Ad Library itself shows and compares it to what was collected. Every query is marked `complete`, `incomplete` or `limit_reached` in the run's OUTPUT.
- 🔁 **Automatic retry:** if fewer than 95% of the ads were collected, it retries with a fresh residential IP (up to 3 attempts).
- 🧹 **Clean, flat output:** one row per ad, no nested JSON digging, and duplicates removed across queries.
- 💸 **Pay only for ads delivered:** $0.65 per 1,000 ads (less on paid Apify plans), platform usage included. Failed or empty runs cost nothing.

**Real example:** for the keyword "sauna blanket" (US, active ads) the Ad Library shows *~620 results*. This Actor paged through to Facebook's own "no more results" marker and returned **583 unique ads**, marked `complete`. The Ad Library count is a rounded estimate, so reaching the end of the list is the proof, and that is what we check.

### Use cases

- **Competitor research:** see every creative a competitor is running right now.
- **Creative inspiration:** collect winning hooks, headlines and CTAs in your niche.
- **E-commerce product research:** find which products brands are pushing with ads.
- **Agencies:** monitor client and competitor ad activity on a schedule.

### Input

| Field | Example |
|---|---|
| Keywords | `["protein powder", "skincare"]` |
| Page IDs | `["15087023444"]` |
| Ad Library URLs | Any `facebook.com/ads/library/?...` URL with filters applied |
| Country | `US`, `GB`, `DE`, or `ALL` |
| Ad status | `active`, `inactive`, `all` |
| Max ads per query | `500` (0 = unlimited) |

### Output (per ad)

```json
{
  "adArchiveId": "1234567890",
  "pageName": "Brand Inc.",
  "isActive": true,
  "startDate": "2026-10-02",
  "platforms": ["FACEBOOK", "INSTAGRAM"],
  "bodyText": "Your skin, but better...",
  "title": "Shop the new serum",
  "ctaText": "Shop Now",
  "linkUrl": "https://brand.com/serum",
  "imageUrls": ["https://..."],
  "videoUrls": [],
  "variationsCount": 4,
  "adLibraryUrl": "https://www.facebook.com/ads/library/?id=1234567890"
}
```

### Run summary (OUTPUT)

```json
{ "summary": [ { "query": "keyword:nike", "reportedCount": 1200, "collected": 1187, "status": "complete" } ] }
```

### Limits

Only publicly visible Ad Library data is collected; no login is used. Meta shows spend and impressions only for political and issue ads, so commercial ads have no spend data, in this scraper or anywhere else.

# Actor input Schema

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

Keywords to search in the Ad Library (e.g. brand or product names).

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

Numeric Page IDs. Returns every ad run by these pages.

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

Paste any URL from facebook.com/ads/library with your filters already applied.

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

Two-letter country code, or ALL.

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

Which ads to include.

## `maxAdsPerQuery` (type: `integer`):

0 = no limit.

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

Residential proxies are recommended; Facebook blocks most datacenter IPs.

## Actor input object example

```json
{
  "searchTerms": [
    "nike"
  ],
  "country": "US",
  "activeStatus": "active",
  "maxAdsPerQuery": 20,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

## `ads` (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": [
        "nike"
    ],
    "maxAdsPerQuery": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("datanest-labs/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"],
    "maxAdsPerQuery": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("datanest-labs/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"
  ],
  "maxAdsPerQuery": 20
}' |
apify call datanest-labs/facebook-ad-library-scraper --silent --output-dataset

```

## MCP server setup

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