# Facebook Ad Library - 5$/month (`insight_api_labs/facebook-ad-library-rental`) Actor

Scrape Facebook ads library reliably and efficiently!

- **URL**: https://apify.com/insight_api_labs/facebook-ad-library-rental.md
- **Developed by:** [InsightAPILabs](https://apify.com/insight_api_labs) (community)
- **Categories:** E-commerce, Social media, Lead generation
- **Stats:** 396 total users, 2 monthly users, 100.0% runs succeeded, 30 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## 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

> **Note:** We now handle proxy management internally for your convenience, as Apify's residential or datacenter proxies may eventually fail when scraping Facebook Ad Library.

Our scraper is ready to dive into Facebook's Ad Library and collect a treasure trove of information for each ad. To get started, you'll need to provide a valid Facebook Ad Library search URL. Here's how to do it:

1. 🌐 Visit https://www.facebook.com/ads/library/
2. 🔍 Perform your desired search, adjusting all the filters to your liking
3. 📋 Copy the resulting URL from your browser's address bar

Make sure that the search URL starts with "https://www.facebook.com/ads/library/" and includes a query keyword (q=...) within it.

You can also programmatically adjust the parameters within the search URL at your workflow via Apify API integration for more flexibility. This opens up exciting possibilities for an automated processing of facebook ad library searches.

### 📊 Data Fields Explained: A Deep Dive into Ad Metrics

#### 🎯 Ad Identification

- **adArchiveID**: Unique identifier for each ad
- **archiveTypes**: Types of archives this ad belongs to
- **categories**: Ad categories for easy classification

#### 📈 Ad Performance

- **impressionsWithIndex**: Insights into ad visibility
- **reachEstimate**: Estimated audience reach
- **spend**: Investment made in the ad campaign

#### 📅 Timeline

- **startDate**: When the ad campaign kicked off
- **endDate**: The campaign's conclusion date

#### 💼 Business Details

- **pageID** & **pageName**: Identifies the advertising entity
- **pageInfo**: Additional details about the advertiser
- **currency**: The monetary unit used for the campaign

#### 🔍 Ad Characteristics

- **containsDigitallyCreatedMedia**: Flags AI-generated content
- **containsSensitiveContent**: Highlights potentially sensitive material
- **gatedType**: Indicates any access restrictions
- **publisherPlatform**: Where the ad is being displayed

#### 🏛️ Compliance & Reporting

- **politicalCountries**: Relevant for political ad transparency
- **isAAAEligible**: Relates to ad archive access
- **reportCount**: User feedback on the ad
- **stateMediaRunLabel**: Important for state media transparency

#### 📸 Content Snapshot

- **snapshot**: A goldmine of ad details! 🏆  <br/><br/>
  | Field | Description |
  |-------|-------------|
  | 📝 Ad Text | Body, title, and captions |
  | 🔗 URLs | Link destinations and CTAs |
  | 🖼️ Images | Original, resized, and watermarked versions |
  | 🎥 Videos | HD and SD video links (when available) |
  | 📊 Page Info | Advertiser details, categories, and stats |
  | 🌐 Instagram | Related Instagram account data |
  | ⏰ Timestamps | Creation time and version history |

  Unlock the full potential of your ad analysis with this comprehensive snapshot! 🚀

#### 🔗 Direct Access

- **url**: Direct link to the ad in Facebook's Ad Library

Plus many more fields that provide a comprehensive view of each ad! 🚀

Here’s the input and output JSON examples for clarity:

#### Input Example

```json
{
  "facebook_ad_library_search_url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TR&q=real estate&search_type=keyword_unordered&media_type=all",
  "total_ads": 100
}
```

#### Output Example

```json
[
  {
    "adArchiveID": "607401198534818",
    "adArchiveId": "607401198534818",
    "adID": null,
    "adId": null,
    "archiveTypes": [],
    "categories": ["UNKNOWN"],
    "containsDigitalCreatedMedia": false,
    "containsDigitallyCreatedMedia": false,
    "containsSensitiveContent": false,
    "collationCount": 1,
    "collationID": "941830434036402",
    "collationId": "941830434036402",
    "currency": "",
    "endDate": 1734595200,
    "endDataFormatted": null,
    "entityType": "PERSON_PROFILE",
    "fevInfo": null,
    "finServAdData": {
      "is_deemed_finserv": false,
      "is_limited_delivery": false
    },
    "finservAdData": {
      "is_deemed_finserv": false,
      "is_limited_delivery": false
    },
    "gatedType": "ELIGIBLE",
    "hasUserReported": false,
    "hiddenSafetyData": false,
    "hideDataStatus": "NONE",
    "impressionsWithIndex": {
      "impressions_text": null,
      "impressions_index": -1
    },
    "isAAAEligible": true,
    "isAaaEligible": true,
    "isAdAccountActioned": null,
    "isActive": true,
    "isProfilePage": false,
    "pageID": "110341895329134",
    "pageId": "110341895329134",
    "pageInfo": "see snapshot for more info about advertiser page",
    "pageIsDeleted": false,
    "pageName": "Good Story",
    "politicalCountries": [],
    "reachEstimate": null,
    "reportCount": null,
    "snapshot": {
      "body": {
        "text": "Hello"
      },
      "branded_content": null,
      "brazil_tax_id": null,
      "byline": null,
      "caption": "fbweb.moboreader.net",
      "cards": [],
      "cta_text": "Learn more",
      "cta_type": "LEARN_MORE",
      "country_iso_code": null,
      "current_page_name": "Good Story",
      "disclaimer_label": null,
      "display_format": "VIDEO",
      "event": null,
      "images": [],
      "is_reshared": false,
      "link_description": null,
      "link_url": "https://fbweb.moboreader.net/64194322-fb_contact-encp30_2-1214-core2.html?adid={{ad.id}}&char=331118&accid=638434121690371&rawadid=120217696994320091",
      "page_categories": ["Book"],
      "page_entity_type": "PERSON_PROFILE",
      "page_id": "110341895329134",
      "page_is_deleted": false,
      "page_is_profile_page": false,
      "page_like_count": 777,
      "page_name": "Good Story",
      "page_profile_picture_url": "https://scontent-mia3-1.xx.fbcdn.net/v/t39.35426-6/470221314_1538773036786543_2843870837120104634_n.jpg",
      "page_profile_uri": "https://www.facebook.com/100090635329790/",
      "root_reshared_post": null,
      "title": null,
      "videos": [
        {
          "video_hd_url": "https://video-mia3-2.xx.fbcdn.net/v/t42.1790-2/470328148_607401218534816_4547189470724049034_n.?",
          "video_preview_image_url": "https://scontent-mia3-1.xx.fbcdn.net/v/t39.35426-6/470209065_2379908972359313_4699088056310665597_n.jpg",
          "video_sd_url": "https://video-mia3-3.xx.fbcdn.net/v/t42.1790-2/469999215_559374680236449_7899133143832632579_n.mp4",
          "watermarked_video_hd_url": "",
          "watermarked_video_sd_url": ""
        }
      ],
      "additional_info": null,
      "ec_certificates": [],
      "extra_images": [],
      "extra_links": [],
      "extra_texts": [],
      "extra_videos": []
    },
    "spend": null,
    "startDate": 1734249600,
    "startDataFormatted": null,
    "stateMediaRunLabel": null,
    "publisherPlatform": ["FACEBOOK", "INSTAGRAM", "AUDIENCE_NETWORK", "MESSENGER"],
    "menuItems": [],
    "facebookUrl": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TR&q=real estate&search_type=keyword_unordered&media_type=all",
    "inputUrl": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TR&q=real estate&search_type=keyword_unordered&media_type=all",
    "url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TR&q=real estate&search_type=keyword_unordered&media_type=all"
  }
]
```

# Actor input Schema

## `facebook_ad_library_search_url` (type: `string`):

Facebook Ad Library Search URL to scrape ads from. It must start with https://www.facebook.com/ads/library/ and contain a search query right after 'q=' parameter in the URL.

## `total_ads` (type: `integer`):

When total number of ads is reached, actor stops retrieving more ads

## `proxy` (type: `object`):

Select proxies to be used by your crawler.

## Actor input object example

```json
{
  "facebook_ad_library_search_url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&q=real estate&search_type=keyword_unordered&media_type=all",
  "total_ads": 100,
  "proxy": {
    "useApifyProxy": true
  }
}
```

# 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 = {
    "facebook_ad_library_search_url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&q=real estate&search_type=keyword_unordered&media_type=all",
    "proxy": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("insight_api_labs/facebook-ad-library-rental").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 = {
    "facebook_ad_library_search_url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&q=real estate&search_type=keyword_unordered&media_type=all",
    "proxy": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("insight_api_labs/facebook-ad-library-rental").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 '{
  "facebook_ad_library_search_url": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&q=real estate&search_type=keyword_unordered&media_type=all",
  "proxy": {
    "useApifyProxy": true
  }
}' |
apify call insight_api_labs/facebook-ad-library-rental --silent --output-dataset

```

## MCP server setup

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

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/paBd2Bv9ONUFkVddB/builds/UfumYCW98YkGZHaph/openapi.json
