# Facebook Ads Library (`perdurable_kitemark/facebook-ads-library`) Actor

Searches the official Meta Ad Library API (ads_archive) and delivers ad records. Pay-per-event: one result charge per delivered ad. Requires your own Meta access token (ads_read); without one the actor explains how to get it.

- **URL**: https://apify.com/perdurable_kitemark/facebook-ads-library.md
- **Developed by:** [Cesar Santana](https://apify.com/perdurable_kitemark) (community)
- **Categories:** Marketing, Social media
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.10 / 1,000 results

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

### What it does

Searches the official **Meta Ad Library API** (`ads_archive` endpoint) and delivers one structured record per ad: creative texts, page, delivery dates, publisher platforms, and more. Uses **your own Meta access token** — it is never shared and is used only to call the Meta API on your behalf. Run it without a token and the actor instead returns step-by-step instructions for getting one.

### Inputs

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `accessToken` | string (secret) | no | — | Your Meta user access token with the `ads_read` permission. Never shared; used only to call the Meta Ad Library API. Leave empty to receive setup instructions. |
| `searchTerms` | string | yes | `software` | Keyword(s) to search for (max 100 characters). |
| `adReachedCountries` | array of strings | yes | `["US"]` | ISO country codes the ads must have reached (required by the Meta API). |
| `adType` | enum | yes | `ALL` | One of `ALL`, `POLITICAL_AND_ISSUE_ADS`, `HOUSING_ADS`, `EMPLOYMENT_ADS`, `FINANCIAL_PRODUCTS_AND_SERVICES_ADS`. The non-`ALL` categories may require extra Meta verification. |
| `maxResults` | integer | yes | `100` | Maximum ads to deliver (1–1000). The API pages 25 ads per request. |

### Outputs

Three record shapes, distinguished by `status`:

**Ad record** (`status: "ok"`) — one per delivered ad:

```json
{
    "status": "ok",
    "adId": "111111111111111",
    "pageId": "222222222222222",
    "pageName": "Acme Software",
    "adSnapshotUrl": "https://www.facebook.com/ads/archive/render_ad/?id=111111111111111",
    "adCreativeBodies": ["Try Acme Software — free for 14 days."],
    "adCreativeLinkCaptions": ["acme.example"],
    "adCreativeLinkDescriptions": ["Project management that stays out of your way."],
    "adCreativeLinkTitles": ["Acme Software — Start free"],
    "adDeliveryStartTime": "2026-09-01",
    "adDeliveryStopTime": null,
    "publisherPlatforms": ["facebook", "instagram"],
    "bylines": ["Acme Inc."],
    "languages": ["en"],
    "fetchedAt": "2026-10-11T00:00:00.000Z"
}
```

**Guidance record** (`status: "auth-required"`) — exactly one, when no token is supplied or Meta rejects it (code 190): `{ "status": "auth-required", "instructions": "..." }`. The run still exits 0.

**Error record** (`status: "failed"`) — one, when the API fails for any other reason: `{ "status": "failed", "reason": "..." }`. With a token present and zero ads delivered, the run fails loudly (non-zero exit) with a token-free reason.

Your token never appears in any dataset record, log line, or error message (snapshot URLs have `access_token` stripped; `paging.next` URLs — which carry the token — are never stored or logged).

### Pricing

Pay-per-event: one **`result`** charge per delivered ad record, fired only after the record is written to the dataset. Guidance and error records are never charged.

**Price: $0.0001 per result ($0.10 per 1,000 results).** Computed 2026-10-12 under the Gate 1 rule from the live platform smoke (run `p2Z8svSHFWW3ZfIv9`): measured platform cost $0.01296 per 1,000 delivered results ($0.0012961 usage / 100 delivered x 1,000) -> 3x floor $0.0389 per 1,000; usage-dominant incumbent ceiling $0.75 per 1,000 (curious_coder, 6,646 users/30d). $0.10/1,000 sits inside the band at ~7.7x measured cost and ~7.5x under the incumbent ceiling.

### Limits

- Official Meta Ad Library API only; requires **your own** token with `ads_read` (see below).
- Subject to Meta's rate limits — on code 613 the actor retries with backoff (20 s, 60 s, 60 s; max 3 retries) then fails loudly.
- Cursor pagination, 25 ads per page; `maxResults` is hard-capped at 1000.
- Only active ads are returned (Meta API default `ad_active_status=ACTIVE`).
- `POLITICAL_AND_ISSUE_ADS` and other regulated categories may require additional Meta verification beyond identity confirmation.

### Getting your Meta token

The Ad Library API does not allow anonymous access — Meta requires every caller to authenticate. Getting a token involves real friction, documented here rather than hidden:

1. **Create a Meta developer account** at [developers.facebook.com](https://developers.facebook.com).
2. **Verify your identity** with Meta (government ID). This review can take **hours to days**.
3. **Create an app** in the developer dashboard.
4. **Add the `ads_read` permission** to the app and generate a **user access token** (e.g. via the Graph API Explorer).
5. **Paste the token** into this actor's `accessToken` input.

The token stays between you and Meta: it is sent only to `graph.facebook.com`, is never logged, and never appears in the output dataset.

### Changelog

#### 0.0.1

- Initial release.

***

House conventions (not actor.json fields — set on the platform at publish):
pay-per-event monetization only; no Standby mode; limited permissions only.
Charge via `Actor.charge({ eventName })` ONLY after a result is delivered;
never charge on failures. Fail loudly (`Actor.fail`) when zero results are
delivered, so broken runs never look successful.

# Actor input Schema

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

Your own Meta (Facebook) user access token with the ads_read permission. It is never shared and is used only to call the Meta Ad Library API on your behalf. Leave empty to get setup instructions instead of results.

## `searchTerms` (type: `string`):

Keyword(s) to search for in the Ad Library (max 100 characters).

## `adReachedCountries` (type: `array`):

ISO country codes the ads must have reached (required by the Meta API).

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

Ad category to search. Note: POLITICAL_AND_ISSUE_ADS, HOUSING_ADS, EMPLOYMENT_ADS and FINANCIAL_PRODUCTS_AND_SERVICES_ADS may require extra Meta verification.

## `maxResults` (type: `integer`):

Maximum number of ads to deliver (hard cap 1000; the API pages 25 ads per request).

## Actor input object example

```json
{
  "searchTerms": "software",
  "adReachedCountries": [
    "US"
  ],
  "adType": "ALL",
  "maxResults": 100
}
```

# 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": "software",
    "adReachedCountries": [
        "US"
    ],
    "adType": "ALL",
    "maxResults": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("perdurable_kitemark/facebook-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": "software",
    "adReachedCountries": ["US"],
    "adType": "ALL",
    "maxResults": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("perdurable_kitemark/facebook-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": "software",
  "adReachedCountries": [
    "US"
  ],
  "adType": "ALL",
  "maxResults": 100
}' |
apify call perdurable_kitemark/facebook-ads-library --silent --output-dataset

```

## MCP server setup

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