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

Download Facebook Ad Library videos for a keyword

Collect active video ads for running shoes shown in the United States, with a direct MP4 link, preview image and duration for every video, plus the ad copy and call to action.

Have the link or ID for a specific ad? Open the single-ad lookup example.

Actor
Facebook Ads Library API & Instagram Ads Scraper
Result limit
20 (maxAds)
Estimated cost
Up to $0.08
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 · facebook-ad-library-video-downloader
{
  "searchQuery": "running shoes",
  "country": "US",
  "activeStatus": "active",
  "mediaType": "video",
  "maxAds": 20
}
Input fields used by this example, their values and what they control
FieldValue in this exampleWhat it controls
searchQueryChange this"running shoes"Find 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.
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.
activeStatus"active"Which ads to return by status. Used for keyword and Page ID searches.
mediaTypeChange this"video"Return only ads with this kind of creative. Used for keyword and Page ID searches.
maxAdsChange this20Maximum 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 (4)
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.
pageIdstringNot specifiedNumeric 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.
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 · searchQuery

    Search keyword

    Find 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.

    Example: "running shoes"

  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 · mediaType

    Media type

    Return only ads with this kind of creative. Used for keyword and Page ID searches.

    Example: "video"

  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: 20

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 “Creatives” view

libraryID

Ad ID

brand

Advertiser

format

Format

multipleVersions

Multiple versions

images

Images

videos

Videos

cards

Cards and versions

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.08: up to 20 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 '{"searchQuery":"running shoes","country":"US","activeStatus":"active","mediaType":"video","maxAds":20}'

Coverage & interpretation

Check the result before relying on it.

Questions

About this example.

What does the "Download Facebook Ad Library videos for a keyword" example collect?

Collect active video ads for running shoes shown in the United States, with a direct MP4 link, preview image and duration for every video, plus the ad copy and call to action. It runs Facebook Ads Library API & Instagram Ads Scraper, published by whoareyouanas on Apify.

Which input does this example use?

Search keyword (searchQuery) set to "running shoes"; Country (country) set to "US"; Media type (mediaType) set to "video"; Maximum ads (maxAds) set to 20. The full JSON input is shown on this page.

How much does it cost to run this example?

At most about $0.08: up to 20 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 Search keyword, Country, Media type, 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.

How do I download the videos?

Each entry in videos has a url that points to the MP4 file on Meta's CDN, a poster preview image and the duration in seconds. Open a link to play or save the file, or loop over the dataset to download every video.

How long do the video links work?

Meta signs its CDN links and they expire, usually within a few days. Download the files soon after the run, or run the task again for fresh links.

Are videos inside carousels and dynamic ads included?

Yes. Videos from every card or version are listed in videos, and each card in cards keeps its own videos with its copy and call to action.

More examples

Related tasks you can copy.

Guides

Read more about this workflow.