# 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
- **Features:** Full permissions
- **Stats:** 142 total users, 3 monthly users, 99.6% runs succeeded, 6 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 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 Scraper

This Apify actor scrapes advertisement data from Facebook's Ad Library over HTTP. No browser/Playwright runtime is required, which keeps runs much cheaper and faster.

### 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/FsFfBRfYbqWeoxiRL/openapi.json
