# Meta Ads Library Scraper (Facebook & Instagram) (`datatrilha/meta-ads-library`) Actor

Collect Facebook and Instagram ads from the public Meta Ad Library by keyword, page ID or URL: ad text, images, videos, carousels, dates, platforms, political spend, and optional EU reach and audience data.

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

## Pricing

from $1.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

## Meta Ads Library Scraper (Facebook & Instagram)

Collect Facebook, Instagram, Messenger and Threads ads from the public [Meta Ad Library](https://www.facebook.com/ads/library/) without logging in. Search by keyword, advertiser page ID or any Ad Library URL and get each ad's text, images, videos, carousel cards, run dates, platforms and links as clean JSON, CSV or Excel. Political ads come with spend, impressions and "paid for by". Optionally add the EU and UK transparency data: total reach, reach by country, age and gender, and the targeted audience.

### What you can use it for

- **Competitor research:** every ad a brand is running right now, with how long each has been live (long-running ads are usually the winners).
- **Creative inspiration:** collect hooks, headlines, calls to action and video files by keyword or niche.
- **EU audience insight:** see how many people an ad reached in the EU and UK, and which ages, genders and countries.
- **Political monitoring:** spend and impressions ranges, and who paid, for political and issue ads (including Brazil's elections).
- **AI agents:** call it as a tool through the Apify MCP server to answer "what is X advertising on Instagram?"

### Input

| Field | What it does |
| --- | --- |
| `searchTerms` | One search per keyword or brand name |
| `pageIds` | Every ad from a Facebook page (the `view_all_page_id` in Ad Library URLs) |
| `startUrls` | Any Ad Library search URL, with the filters you set on the site |
| `country` | Two-letter code such as `BR`, `US`, `FR`, or `ALL` |
| `adType` | All ads, political and issue, housing, employment or financial ads |
| `activeStatus` | Active, inactive or both |
| `mediaType` | Images, videos, memes or no media |
| `exactPhrase` | Match the search term as an exact phrase |
| `maxAdsPerSearch` | Cap per search (default 100) |
| `includeAdDetails` | Add EU/UK reach and audience, payer and page details (separate charge per ad) |

### Output

```json
{
  "adArchiveId": "1537869851003613",
  "adLibraryUrl": "https://www.facebook.com/ads/library/?id=1537869851003613",
  "pageId": "739783715881879",
  "pageName": "BagIt",
  "pageLikeCount": 804,
  "isActive": true,
  "startDate": "2026-05-19T07:00:00.000Z",
  "publisherPlatforms": ["FACEBOOK", "INSTAGRAM", "AUDIENCE_NETWORK", "MESSENGER", "THREADS"],
  "displayFormat": "VIDEO",
  "bodyText": "Pourquoi tes baskets blanches ne sont jamais vraiment propres ? ...",
  "title": "Des baskets propres. Sans effort.",
  "linkUrl": "https://www.shopbagit.com/products/sac-de-lavage-bagit",
  "ctaText": "Shop now",
  "videos": [{ "hdUrl": "https://video.xx.fbcdn.net/...mp4", "sdUrl": "https://...", "previewImageUrl": "https://..." }],
  "searchKey": "search:nike",
  "totalResults": 5558,
  "scrapedAt": "2026-10-31T21:00:00.000Z"
}
```

With `includeAdDetails` on, ads shown in the EU or UK also get:

```json
{
  "euTransparency": {
    "totalReach": 53516,
    "ageMin": 21, "ageMax": 65, "gender": "All",
    "locations": [{ "name": "Ireland", "type": "countries", "excluded": false }],
    "reachByCountryAgeGender": [{ "country": "PT", "ageRange": "45-54", "male": 219, "female": 12, "unknown": 3 }]
  },
  "payerBeneficiaries": [{ "payer": "Example Ltd", "beneficiary": "Example Ltd" }]
}
```

### Pricing

You pay per ad returned, plus a separate event per ad when you ask for EU/UK details. Media files are linked, not downloaded, so runs stay cheap.

### Notes

- Media URLs from Meta's CDN expire after some days. Download what you need soon after the run.
- Meta groups near-identical ads; `collationCount` tells you how many ads share the creative.
- Only public Ad Library data is collected. No login, no personal profiles.

### Development

`npm test` runs the parsers against real responses saved in `fixtures/` (captured from a residential IP; see `fixtures/NOTES.md`). `tools/capture` is the script that captured them.

# Actor input Schema

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

Keywords or advertiser names to search in the Ad Library. One search per term.

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

Numeric Facebook page IDs. Returns every ad from that page, the most precise way to monitor one advertiser. Find it in the Ad Library URL as view_all_page_id.

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

Search URLs copied from facebook.com/ads/library, with any filters you set there. Single-ad URLs (?id=) work too.

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

Two-letter country code where the ads ran, for example BR, US, FR. ALL searches every country.

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

Political and issue ads include spend, impressions and who paid for them.

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

Only active ads, only inactive ads, or both.

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

Filter by creative type.

## `exactPhrase` (type: `boolean`):

Match the search term as an exact phrase instead of any of its words.

## `maxAdsPerSearch` (type: `integer`):

Stop each search after this many ads. You pay only for ads returned.

## `includeAdDetails` (type: `boolean`):

Fetch each ad's transparency data: total EU and UK reach, reach by country, age and gender, targeted age, gender and locations, and who paid. Meta publishes this for ads shown in the EU and UK. Charged as a separate event per ad.

## `delaySecs` (type: `integer`):

Pause between requests to Meta. Lower is faster but gets rate limited more often.

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

Residential proxies are recommended; Meta challenges datacenter IPs more often.

## Actor input object example

```json
{
  "searchTerms": [
    "nike"
  ],
  "country": "ALL",
  "adType": "all",
  "activeStatus": "active",
  "mediaType": "all",
  "exactPhrase": false,
  "maxAdsPerSearch": 100,
  "includeAdDetails": false,
  "delaySecs": 1,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

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

All collected ads with every field.

## `overview` (type: `string`):

Main fields in a table.

## `transparency` (type: `string`):

Political spend and impressions, and EU/UK reach and audience when requested.

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

// Run the Actor and wait for it to finish
const run = await client.actor("datatrilha/meta-ads-library").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"],
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    },
}

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

```

## MCP server setup

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

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/Fb9cCnRkCmhdM4ReI/builds/qYhUWnK2OnfjeVtPu/openapi.json
