Apify example task · whoareyouanas/facebook-ads-library-api

View a competitor's Facebook ads by Page ID

View and export the active Facebook and Instagram ads of one competitor, Burger King in the United States, by its Facebook Page ID. Swap in your competitor's Page ID to analyze their creatives.

Actor
Facebook Ads Library API & Instagram Ads Scraper
Result limit
50 (maxAds)
Estimated cost
Up to $0.20
Run options
0.5 GB memory · 300 s timeout

Example updated 2026-11-23 · actor build 0.2.10 · runs in your own Apify account

01 / About the actor

Facebook Ads Library API & Instagram Ads Scraper

Facebook Ads Library API for developers and AI agents. Search Facebook and Instagram ads by keyword, Page ID or Ad Library URL and get ad copy, images, videos, CTAs, landing pages and dates as JSON in seconds. No Meta token, login or proxy setup. Exact ad limits. MCP-ready.

One focused search

Use one keyword, Page ID, or direct search URL per run.

Bound the ad sample

Set maxAds rather than relying on Meta's approximate displayed result count.

Keep creative structure

Review image, video, carousel, and dynamic creative fields in JSON or dataset exports.

02 / Input

The exact input this example runs.

Provide targetUrl, searchQuery, or pageId and set maxAds for the unique-ad cap. Use the documented country, status, media, and date filters where applicable. The current Actor uses built-in proxies and ignores the legacy proxyConfiguration field.

input.json · competitor-facebook-page-ads
{
  "pageId": "134615383218473",
  "country": "US",
  "activeStatus": "active",
  "maxAds": 50
}
Input fields used by this example, their values and what they control
FieldValue in this exampleWhat it controls
pageIdChange this"134615383218473"Numeric Facebook Page ID of one advertiser, the number after view_all_page_id= in its Ad Library URL. Takes precedence over the keyword example. A search URL takes precedence over this field.
countryChange this"US"Two-letter country code where the ads were shown, such as US, GB, IN or DE, or ALL for every country. Used for keyword and Page ID searches.
activeStatusChange this"active"Which ads to return by status. Used for keyword and Page ID searches.
maxAdsChange this50Maximum unique ads to deliver in this run, from 1 to 10,000. You pay only for ads delivered, and the run stops exactly at this limit.
Other inputs you can add (5)
Deployed actor input fields, types, defaults, and descriptions
FieldType / requiredDefaultPurpose
targetUrlstringNot specifiedPaste any Meta Ad Library search URL from your browser. It takes precedence over Page ID and keyword, and its filters (country, status, platforms, sort, date range) take precedence over the form. Tracking parameters such as fbclid are removed automatically. To look up one ad by its ID, use our Facebook Ad Library Single Ad Lookup.
searchQuerystringNot specifiedFind ads that mention a keyword, brand or product, for example nike or protein powder. The example searches nike. A URL or Page ID takes precedence when provided.
mediaTypestring"all"Return only ads with this kind of creative. Used for keyword and Page ID searches.

Options: all, image, video, meme, none

dateFromstringNot specifiedFirst day of the range, YYYY-MM-DD. Leave empty for no start limit.
dateTostringNot specifiedLast day of the range, YYYY-MM-DD. Leave empty for no end limit.

03 / Make it yours

Change these fields for your own research.

  1. 01 · pageId

    Facebook Page ID

    Numeric Facebook Page ID of one advertiser, the number after view_all_page_id= in its Ad Library URL. Takes precedence over the keyword example. A search URL takes precedence over this field.

    Example: "134615383218473"

  2. 02 · country

    Country

    Two-letter country code where the ads were shown, such as US, GB, IN or DE, or ALL for every country. Used for keyword and Page ID searches.

    Example: "US"

  3. 03 · activeStatus

    Ad status

    Which ads to return by status. Used for keyword and Page ID searches.

    Example: "active"

  4. 04 · maxAds

    Maximum ads

    Maximum unique ads to deliver in this run, from 1 to 10,000. You pay only for ads delivered, and the run stops exactly at this limit.

    Example: 50

Run it in three steps

  1. Open the example on Apify and select Try for free to copy it into your Apify account.
  2. Replace the sample values above with your own target and keep the limit small.
  3. Start the run, then export the dataset as JSON, CSV or Excel.

04 / Output

What the results table shows.

Columns in the “Ads” view

libraryID

Ad ID

brand

Advertiser

pageId

Page ID

active

Active

body

Ad copy

linkTitle

Headline

ctaText

Call to action

linkUrl

Landing page

format

Format

platforms

Platforms

startDate

Started

endDate

Ended

collaboratorName

Partnership creator

images

Images

videos

Videos

adLibraryUrl

View ad

A view selects columns for the table. The full JSON export keeps every field, including nested arrays and objects.

05 / Cost

What this example costs to run.

At most about $0.20: up to 50 results at $0.004 each (Ad). Fewer results cost less. The live Pricing tab on Apify is authoritative.

Prices checked 2026-11-24. Set a run spending limit in Apify when you widen the input.

06 / API

Run the same input from your code.

This call starts a billable run of Facebook Ads Library API & Instagram Ads Scraper with this example's input and returns the dataset items when it finishes. Synchronous calls wait up to five minutes; for longer runs, POST to /runs instead and read the run's default dataset when it succeeds. Keep the token in an environment variable.

cURL · run and return the results
curl --request POST \
  'https://api.apify.com/v2/acts/whoareyouanas~facebook-ads-library-api/run-sync-get-dataset-items?format=json' \
  --header "Authorization: Bearer $APIFY_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{"pageId":"134615383218473","country":"US","activeStatus":"active","maxAds":50}'

Coverage & interpretation

Check the result before relying on it.

Questions

About this example.

What does the "View a competitor's Facebook ads by Page ID" example collect?

View and export the active Facebook and Instagram ads of one competitor, Burger King in the United States, by its Facebook Page ID. Swap in your competitor's Page ID to analyze their creatives. It runs Facebook Ads Library API & Instagram Ads Scraper, published by whoareyouanas on Apify.

Which input does this example use?

Facebook Page ID (pageId) set to "134615383218473"; Country (country) set to "US"; Ad status (activeStatus) set to "active"; Maximum ads (maxAds) set to 50. The full JSON input is shown on this page.

How much does it cost to run this example?

At most about $0.20: up to 50 results at $0.004 each (Ad). Fewer results cost less. The live Pricing tab on Apify is authoritative.

How do I change it for my own research?

Open the example on Apify and select Try for free to copy it into your account, then edit Facebook Page ID, Country, Ad status, Maximum ads. Keep the result limit small for the first run and check the output before scaling up.

Can I run it from the API or on a schedule?

Yes. Send the same JSON input to the Facebook Ads Library API & Instagram Ads Scraper run endpoint with your Apify API token, or save the copied task in your Apify account and add a schedule. Results land in the run's default dataset as JSON, CSV or Excel.

Where do I find a Page ID?

Open the advertiser in the Meta Ad Library: the Page ID is the number after view_all_page_id= in the URL. Our Facebook Page ID Finder Actor turns a brand name into a Page ID.

Does this return only that advertiser's ads?

Yes. A Page search returns ads run by that Page, including partnership ads where a creator ran the ad on its behalf; those name the creator in collaboratorName. Stray records from other Pages are skipped and counted in the run summary.

How do I track the competitor over time?

Save this as your own task and schedule it daily or weekly. Each run produces a new dataset; compare Library IDs between runs to see new and stopped ads.

More examples

Related tasks you can copy.

Guides

Read more about this workflow.