# Facebook Ads Library Scraper Pro: Meta Ads by Keyword/Page (`muarafa/facebook-ads-library-pro`) Actor

Scrape ads from Meta's public Ad Library by keyword, Page ID or ready-made URL. Full ad text, images & videos, CTA, links, platforms, dates, copies count, spend & impressions. Duplicates and failures never charged. $0.002 per ad.

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

## Pricing

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

## Facebook Ads Library Scraper Pro – Meta Ads by Keyword, Page or URL

Get ads from Meta's **public Ad Library** (facebook.com/ads/library) by **keyword, Facebook Page ID or a ready-made Ad Library link**. Every ad comes with its **full text, headline, call-to-action, landing page, images & videos, platforms, run dates, number of copies**, and **spend & impressions** when Meta publishes them. Export to **JSON, CSV or Excel** in one click. Duplicates and failed requests are **never charged**.

**$0.002 per ad** ($2 per 1,000 ads), only for new, successfully delivered ads.

### Why this scraper?

| Typical problem | Facebook Ads Library Scraper Pro |
|---|---|
| Runs return empty when the page refuses a request | Retries automatically with a **fresh browser session and new proxy IP** on any empty or refused response |
| Only the first handful of ads | Follows the page's own infinite scroll – thousands of ads per query |
| Truncated ad copy | **Full ad text**, headline, link description, CTA and display URL |
| Media missing | All **images and videos** (HD video URL + thumbnail), carousels included |
| Same ad counted many times | De-duplicated by `ad_archive_id`; `ad_count_in_group` tells you how many copies exist |
| Paying for nothing | No results = clear reason in the log and **$0** |
| Need a login / cookies | **None.** Only the public page that opens without signing in |

### Input

Provide at least one of `searchTerms`, `pageIds` or `urls`.

```json
{
  "searchTerms": ["nike", "shopify"],
  "pageIds": ["15087023444"],
  "urls": [
    { "url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=video&q=nike&search_type=keyword_unordered" }
  ],
  "country": "US",
  "adType": "all",
  "activeStatus": "active",
  "mediaType": "all",
  "startDate": "2025-01-01",
  "endDate": "2026-12-31",
  "language": "en",
  "maxAdsPerQuery": 100,
  "maxTotalAds": 1000
}
```

- **searchTerms / pageIds / urls** – any mix; each entry is its own query. Ready-made URLs keep the filters you set in the browser.
- **country** – 2-letter code or `ALL` (default).
- **adType** – `all` or `political_and_issue`.
- **activeStatus** – `active` (default), `inactive` or `all`.
- **mediaType** – `all`, `image` or `video`.
- **startDate / endDate** – ads that started within this window (`YYYY-MM-DD`).
- **language** – ad content language code.
- **maxAdsPerQuery** (default 100) and **maxTotalAds** (default 1000) – hard limits.
- **proxyConfiguration** – Apify Proxy (recommended). Switch to the `RESIDENTIAL` group if your datacenter IPs get refused.
- **accessToken** – optional, see [Official API fallback](#official-api-fallback).

### Output example

```json
{
  "ad_archive_id": "1885140209512519",
  "page_id": "15087023444",
  "page_name": "Nike",
  "page_profile_url": "https://www.facebook.com/nike/",
  "ad_library_url": "https://www.facebook.com/ads/library/?id=1885140209512519",
  "status": "active",
  "start_date": "2026-09-09",
  "end_date": "2026-10-25",
  "platforms": ["facebook", "instagram"],
  "ad_text": "Built for the long run. Meet the new Pegasus.",
  "headline": "Nike Pegasus 42",
  "link_description": null,
  "cta_type": "SHOP_NOW",
  "cta_text": "Shop now",
  "link_url": "https://www.nike.com/running",
  "display_url": "nike.com",
  "display_format": "VIDEO",
  "media": [
    { "type": "video", "url": "https://video.xx.fbcdn.net/….mp4", "thumbnail_url": "https://scontent.xx.fbcdn.net/….jpg" }
  ],
  "ad_count_in_group": 4,
  "is_political": false,
  "spend": null,
  "impressions": null,
  "currency": null,
  "page_like_count": 39000000,
  "page_categories": ["Sportswear Store"],
  "scraped_at": "2026-10-26T01:00:00.000Z"
}
```

`spend`, `impressions` and `currency` are filled whenever Meta publishes them (mainly political and issue ads). `display_format` can be `IMAGE`, `VIDEO`, `CAROUSEL`, `DCO` or `DPA` (dynamic ads). Media URLs are Meta CDN links that expire after a while – download them if you need to keep them.

#### Export

Open the run's **Dataset** and download as **JSON, CSV, Excel (XLSX)**, HTML, XML or RSS – or fetch it via the API.

### How it works (and what it will not do)

The Actor opens the public Ad Library page – the one that works without signing in – in a real browser, reads the ads from the page's own data and follows its infinite scroll. It **never logs in, never uses account cookies, never solves CAPTCHAs and never works around protections**. When a response comes back empty or refused, it simply tries again with a new session (and a new proxy IP).

#### Official API fallback

If the public page were ever closed completely, paste an access token for Meta's official [Ad Library API](https://www.facebook.com/ads/library/api/) into `accessToken`. The Actor then serves the same query through the API. This path returns the fields the API offers (text, headline, dates, platforms, spend/impressions where available, snapshot link) but no media files or CTA. It is used only after the public page failed and only if you provide a token.

### Pricing

Pay-per-event: **one `ad` event = $0.002** per unique ad delivered to the dataset = **$2 per 1,000 ads**.

- Duplicate ads (same `ad_archive_id`) are charged once per run.
- Failed or empty requests are not charged.
- The Actor respects your **maximum cost per run** and stops politely when it is reached.

Platform usage (compute, proxy) is included in the event price on Apify's pay-per-event model.

### Use cases

- **Competitor research** – see every creative and message a brand is running right now
- **Creative inspiration** – filter by video or image, country and language
- **Ad monitoring** – schedule daily runs and track new launches by page
- **Political & issue ad transparency** – spend and impressions ranges where published
- **Agencies & AI pipelines** – feed ad copy and media into dashboards, swipe files and LLM analysis

### FAQ

**Do I need a Facebook account?** No.

**Why fewer results than the Ad Library website shows?** Each query is limited by *Max ads per query*; raise it, or split by country, date range or media type.

**Why is `spend` empty?** Meta publishes spend and impressions mainly for political and issue ads.

**Can I call it from code, Make, Zapier, n8n or an AI agent?** Yes – via the Apify API, clients and integrations.

Ad Library data is public information published by Meta. You are responsible for using it in line with applicable laws and Meta's terms.

# Actor input Schema

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

Keywords or brand names to search in the Meta Ad Library, e.g. <code>nike</code>, <code>shopify</code>. One search per keyword. Provide at least one of <b>Search keywords</b>, <b>Page IDs</b> or <b>Ad Library URLs</b>.

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

Numeric Facebook Page IDs to get all ads of one advertiser (e.g. Nike = <code>15087023444</code>). You can find the ID in the Ad Library URL as <code>view_all_page_id=…</code>.

## `urls` (type: `array`):

Ready-made Ad Library links (<code>https://www.facebook.com/ads/library/?…</code>) with any filters you already set in the browser. Their own filters are used as they are.

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

Country where the ads were shown, as a 2-letter ISO code (<code>US</code>, <code>GB</code>, <code>DE</code>, <code>EG</code>…) or <code>ALL</code> for every country. Applies to keywords and Page IDs.

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

All ads, or only political and issue ads (these also include spend and impressions ranges).

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

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

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

Restrict to ads with images or with videos.

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

Only ads that started running on or after this date (<code>YYYY-MM-DD</code>).

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

Only ads that started running on or before this date (<code>YYYY-MM-DD</code>).

## `language` (type: `string`):

Optional language code of the ad content (<code>en</code>, <code>es</code>, <code>ar</code>, <code>fr</code>…). Leave empty for all languages.

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

Stop each query after this many new ads.

## `maxTotalAds` (type: `integer`):

Hard cap for the whole run. You are charged only for ads actually delivered, never for duplicates or failures.

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

Apify Proxy is recommended. Datacenter proxies are tried by default; pick the <code>RESIDENTIAL</code> group if Meta refuses requests from your IPs.

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

When a response comes back empty or refused, the scraper retries with a brand-new browser session and proxy IP up to this many times.

## `accessToken` (type: `string`):

Only used if the public Ad Library page is completely unavailable. Create a token for Meta's official <a href="https://www.facebook.com/ads/library/api/">Ad Library API</a>; the Actor then fetches the same query from the API (fewer fields: no media files or CTA).

## Actor input object example

```json
{
  "searchTerms": [
    "nike",
    "shopify",
    "running shoes"
  ],
  "pageIds": [
    "15087023444"
  ],
  "urls": [
    {
      "url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=video&q=nike&search_type=keyword_unordered"
    }
  ],
  "country": "US",
  "adType": "all",
  "activeStatus": "active",
  "mediaType": "all",
  "startDate": "2025-01-01",
  "endDate": "2026-12-31",
  "language": "en",
  "maxAdsPerQuery": 100,
  "maxTotalAds": 1000,
  "proxyConfiguration": {
    "useApifyProxy": true
  },
  "maxRetries": 4
}
```

# Actor output Schema

## `results` (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",
        "shopify"
    ],
    "pageIds": [],
    "urls": [],
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("muarafa/facebook-ads-library-pro").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",
        "shopify",
    ],
    "pageIds": [],
    "urls": [],
    "proxyConfiguration": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("muarafa/facebook-ads-library-pro").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",
    "shopify"
  ],
  "pageIds": [],
  "urls": [],
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}' |
apify call muarafa/facebook-ads-library-pro --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,muarafa/facebook-ads-library-pro"
        }
    }
}
```

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/4LLe5w2l7Td35BlWQ/builds/ultekWuOmpOfeuRPz/openapi.json
