1. Tutorials
  2. How to scrape Facebook Ad Library ad transcript

How to scrape Facebook Ad Library ad transcript

Get Facebook Ad Library ad transcript as JSON with one request. Captions cost 1 credit.

Get an API key; the examples use api.socialscrape.dev.

Before you start

Step 1: Send the request

GET /v1/facebook/ad-library/ad/transcript. Pick your language; each one reads the key from SOCIALSCRAPE_API_KEY.

1curl -G "https://api.socialscrape.dev/v1/facebook/ad-library/ad/transcript" \2  -H "x-api-key: $SOCIALSCRAPE_API_KEY" \3  --data-urlencode 'id=352695862528588'

Step 2: Read the response

The result is in data. Here is what the object gives you, from a recorded sample.

1print(body["data"]["text"])
SampleFields printed above
1{2  "text": "canned transcript for the fixture, not the ad's real audio"3}

A field the platform does not give comes back as null. The full field list is on the endpoint page.

Step 3: Handle errors

Check ok, then branch on error.code and error.retryable, never on the message.

1body = res.json()2if not body["ok"]:3    err = body["error"]4    if err["retryable"]:5        ...  # wait a moment and send the same request again6    else:7        raise RuntimeError(f'{err["code"]}: {err["message"]}')
CodeHTTPRetryMeaning
invalid_params400noA parameter is missing, unknown or has the wrong type.
unsupported_url400noThe URL is not one this endpoint accepts (wrong platform or form).
not_found404noThe platform says this profile, post or item does not exist.
transcript_unavailable404noNo captions exist and AI transcription is not possible for this media.

Other errors, such as unauthorized or rate_limited, are on the errors page.

With the SDK

The Python and TypeScript clients wrap all of this: typed errors, retries. Install them with pip install socialscrape-sdk or npm install socialscrape.

1from socialscrape import SocialScrape23client = SocialScrape()  # reads SOCIALSCRAPE_API_KEY45res = client.facebook.ad_library_ad_transcript(id="352695862528588")6print(res.data)7print(res.credits_charged, res.credits_remaining)

What it costs

1 credit for captions; AI transcription 1 up to 2 minutes, then 5 per started minute of the whole video. A failed request costs nothing. Add max_age_days to reuse a cached result for 0 credits. Results are kept 30 days.

Next

Questions

Which language should I use?

Any. It is plain HTTP and JSON, so every language with an HTTP client works. The tabs show the same request nine ways.