# Facebook Ads (`shareze001/facebook-ads`) Actor

You can retrieve ads by keyword or advertiser ID, with the advertiser ID available through `actor: shareze001/facebook-advertisers`. Additionally, you can filter ads based on time range and ad status for more specific results.

- **URL**: https://apify.com/shareze001/facebook-ads.md
- **Developed by:** [shareze](https://apify.com/shareze001) (community)
- **Categories:** E-commerce, Social media, Other
- **Stats:** 139 total users, 2 monthly users, 100.0% runs succeeded, 6 bookmarks
- **User rating**: No ratings yet

## Pricing

$9.99/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month after the free trial period. You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Facebook Ads Scraper

This Apify actor is designed to scrape advertisement data from Facebook's Ad Library using Playwright. It allows you to search for ads based on keywords, page IDs, and other parameters.

### How to Use

#### Input Configuration

The actor accepts the following input parameters in JSON format:

| Parameter       | Type     | Description                                                                 | Required | Default Value |
|------------------|----------|-----------------------------------------------------------------------------|----------|---------------|
| `size`          | Integer  | The maximum number of ads to scrape.                                        | Yes      | 10            |
| `keyword`       | String   | The search keyword for finding ads.                                         | No       |               |
| `page_id`       | String   | The advertiser's page ID. You can get it using the `shareze001/facebook-advertisers` actor. | No       | 15087023444   |
| `ad_status`     | String   | The status of the ads to scrape (`all`, `active`, or `inactive`).           | Yes      | `all`         |
| `country`       | String   | The country filter for the ads (`ALL` or `US`).                            | Yes      | `ALL`         |
| `start_date_min`| String   | The start date for filtering ads (format: `YYYY-MM-DD`).                   | No       |               |
| `start_date_max`| String   | The end date for filtering ads (format: `YYYY-MM-DD`).                     | No       |               |

#### Example Input

```json
{
    "size": 20,
    "keyword": "shoes",
    "page_id": "123456789",
    "ad_status": "active",
    "country": "US",
    "start_date_min": "2023-01-01",
    "start_date_max": "2023-01-31"
}
```

#### Output

The actor returns an array of scraped ads in JSON format. Each ad contains the following fields:

- `ad_archive_id`: The unique ID of the ad in the Facebook Ad Library.
- `collation_id`: The collation ID of the ad.
- `collation_count`: The number of ads in the collation.
- `start_date`: The start date of the ad.
- `end_date`: The end date of the ad.
- `page_id`: The ID of the advertiser's page.
- `page_name`: The name of the advertiser's page.
- `page_like_count`: The number of likes on the advertiser's page.
- `page_profile_picture_url`: The URL of the advertiser's profile picture.
- `page_is_deleted`: Whether the advertiser's page is deleted.
- `publisher_platform`: The platform where the ad is published.
- `is_aaa_eligible`: Whether the ad is eligible for AAA.
- `is_active`: Whether the ad is currently active.
- `body`: The text content of the ad.
- `images`: A list of image URLs used in the ad.
- `videos`: A list of video details used in the ad.
- `links`: A list of links included in the ad.

#### Example Output

```json
[
    {
        "ad_archive_id": "1234567890",
        "collation_id": "0987654321",
        "collation_count": 1,
        "start_date": "2023-01-01",
        "end_date": "2023-01-31",
        "page_id": "123456789",
        "page_name": "Example Page",
        "page_like_count": 1000,
        "page_profile_picture_url": "https://example.com/profile.jpg",
        "page_is_deleted": false,
        "publisher_platform": "Facebook",
        "is_aaa_eligible": true,
        "is_active": true,
        "body": "This is an example ad.",
        "images": ["https://example.com/image1.jpg"],
        "videos": [
            {
                "video_preview_image_url": "https://example.com/video_preview.jpg",
                "video_url": "https://example.com/video.mp4"
            }
        ],
        "links": [
            {
                "title": "Example Link",
                "description": "This is an example link.",
                "url": "https://example.com/",
                "caption": "Example Caption",
                "button_text": "Learn More"
            }
        ]
    }
]
```

#### Running the Actor

1. Deploy the actor to the Apify platform.
2. Provide the input parameters in the actor's input schema.
3. Run the actor and wait for the results.
4. Download the output data in JSON format.

#### Use Cases

- Analyze Facebook ads for market research.
- Monitor competitors' advertising strategies.
- Collect data for ad performance analysis.

# Actor input Schema

## `size` (type: `integer`):

advertisement size

## `keyword` (type: `string`):

search keyword

## `page_id` (type: `string`):

Advertiser id, you can get it through actor: `shareze001/facebook-advertisers`.

## `ad_status` (type: `string`):

Ad status

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

Country

## `start_date_min` (type: `string`):

Select start date in format YYYY-MM-DD

## `start_date_max` (type: `string`):

Select end date in format YYYY-MM-DD

## Actor input object example

```json
{
  "size": 10,
  "page_id": "15087023444",
  "ad_status": "all",
  "country": "ALL"
}
```

# 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 = {
    "size": 10,
    "page_id": "15087023444"
};

// Run the Actor and wait for it to finish
const run = await client.actor("shareze001/facebook-ads").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 = {
    "size": 10,
    "page_id": "15087023444",
}

# Run the Actor and wait for it to finish
run = client.actor("shareze001/facebook-ads").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 '{
  "size": 10,
  "page_id": "15087023444"
}' |
apify call shareze001/facebook-ads --silent --output-dataset

```

## MCP server setup

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

```

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/yhoz5tLd6h8XSuUP7/builds/q0K4xlUyvE9LK8qKs/openapi.json
