How to Scrape Facebook Ad Library Ad Details with Rust
Get Facebook Ad details by Ad ID using Rust. This comprehensive guide will walk you through the entire process, from setup to implementation.
Overview
What You'll Learn
- Setting up your Rust environment
- Installing the required HTTP client
- Authenticating with SociaVault API
- Making requests to Facebook Ad Library
- Handling responses and errors
What You'll Get
- Access to ad details data
- JSON formatted responses
- Real-time data access
- Scalable solution
- Error handling patterns
Prerequisites
1. API Key
First, you'll need a SociaVault API key to authenticate your requests.
2. Development Environment
Make sure you have the following installed:
- Rust installed
- A code editor (VS Code, Sublime, etc.)
- Command line interface access
Implementation
Step 1: Install HTTP Client
We'll use reqwest to make HTTP requests.
cargo add reqwest tokioStep 2: API Implementation
Now let's make a request to the Facebook Ad Library API using Rust. Replace YOUR_API_KEY with your actual API key.
use reqwest;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let resp = client.get("https://api.sociavault.com/facebook-ad-library/ad-details?id=123456789")
.header("x-api-key", "YOUR_API_KEY")
.header("Content-Type", "application/json")
.send()
.await?
.text()
.await?;
println!("{}", resp);
Ok(())
}Testing Your Code
API Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | string | Yes | Example: 123456789 |
Expected Response
You should receive a structured JSON response containing the ad details data.
{
"adid": 0,
"adArchiveID": 702369045530963,
"categories": [
0
],
"containsDigitallyCreatedMedia": false,
"containsSensitiveContent": false,
"currency": "",
"endDate": 1747983600,
"entityType": "person_profile",
"finServAdData": {
"is_deemed_finserv": false,
"is_limited_delivery": false
},
"gatedType": "eligible",
"hasUserReported": false,
"hiddenSafetyData": false,
"hideDataStatus": "NONE",
"impressionsWithIndex": {
"impressionsIndex": -1
},
"isAAAEligible": true,
"isAdAccountActioned": false,
"isActive": false,
"isProfilePage": false,
"pageID": 166258896830103,
"pageIsDeleted": false,
"pageName": "Porto Montenegro",
"regionalRegulationData": {
"finserv": {
"is_deemed_finserv": false,
"is_limited_delivery": false
},
"tw_anti_scam": {
"is_limited_delivery": false
}
},
"snapshot": {
"ad_creative_id": 1066536401993375,
"caption": "www.portomontenegro.com",
"cta_text": "Learn more",
"effective_authorization_category": "NONE",
"display_format": "video",
"link_url": "https://www.portomontenegro.com/attractions-events/boka-place-grand-opening/",
"videos": [
{
"video_hd_url": "https://video-lga3-1.xx.fbcdn.net/v/t42.1790-2/491479560_702369072197627_5775200790449116407_n.?_nc_cat=111&ccb=1-7&_nc_sid=c53f8f&_nc_ohc=hwX4c3kvwLsQ7kNvwFl2d_Q&_nc_oc=AdlG8xo51B_VLh8mOjXqjG0Mad3sb7Q-j-8ZZzP-s_j3sHdDkDUJwrrmYd7R9UyfaOA&_nc_zt=28&_nc_ht=video-lga3-1.xx&_nc_gid=PBbgsjxhy8iorGrJjaavZw&oh=00_AfKBmgSKPootHiGNb9xgL2zB15Omax_hVTaa2bzRsjzn_w&oe=6843812F",
"video_sd_url": "https://video-lga3-1.xx.fbcdn.net/v/t42.1790-2/499448662_702369075530960_5981246750517589666_n.?_nc_cat=103&ccb=1-7&_nc_sid=c53f8f&_nc_ohc=cg4ziP_jjpkQ7kNvwEd7Ymr&_nc_oc=AdlMwa_AeLm6TknZdG_S5L26DNIi_LeoUM_iw58qxM3z4hkKIeJOinIjGuvP4T1zl8I&_nc_zt=28&_nc_ht=video-lga3-1.xx&_nc_gid=PBbgsjxhy8iorGrJjaavZw&oh=00_AfK-DFpMEBShiZb3JUsjv_0EAC7saMqut0dI5fJGTAK8hQ&oe=6843A9D6",
"watermarked_video_sd_url": "",
"watermarked_video_hd_url": "",
"video_preview_image_url": "https://scontent-lga3-1.xx.fbcdn.net/v/t39.35426-6/499149696_1837810423819060_5242520759436861939_n.jpg?_nc_cat=111&ccb=1-7&_nc_sid=c53f8f&_nc_ohc=h-Gc3OVWRsQQ7kNvwENP9GF&_nc_oc=AdnHZtuO7JE08Yptly2LO3_sk-XEiw2Dx_ZHE2FyzV8AY1Y-zm24L3Na7ap1rdpO-f8&_nc_zt=14&_nc_ht=scontent-lga3-1.xx&_nc_gid=PBbgsjxhy8iorGrJjaavZw&oh=00_AfKr3Go0i5YNKCoOfapvk0fO7DxfBFYazfPdNnjbBHnnEA&oe=684381BA"
}
],
"creation_time": 1747908203,
"page_id": 598631456674530,
"page_name": "Porto Montenegro Experience",
"page_profile_picture_url": "https://scontent-lga3-3.xx.fbcdn.net/v/t39.35426-6/498588182_739875508369121_8639482247199838788_n.jpg?stp=dst-jpg_s60x60_tt6&_nc_cat=110&ccb=1-7&_nc_sid=c53f8f&_nc_ohc=CL4JqnVkRzgQ7kNvwEVYWpq&_nc_oc=AdkdPEIQctV4dKggCb8YIFBwzdb5ghgYdYUDAEqQ8mcGtCVOr3QZZ_-kg9lil60EMOg&_nc_zt=14&_nc_ht=scontent-lga3-3.xx&_nc_gid=PBbgsjxhy8iorGrJjaavZw&oh=00_AfIJsuOZfJyoWeHNlOp18Nn7Y1xmM79egJLCXKItT0-qjQ&oe=68439344",
"page_categories": {
"197251360301109": "Marina"
},
"page_entity_type": "person_profile",
"page_is_profile_page": false,
"instagram_actor_name": "Porto Montenegro Experience",
"instagram_profile_pic_url": "https://scontent-lga3-2.xx.fbcdn.net/v/t39.35426-6/499922917_1078294804160843_5583552140592065526_n.jpg?_nc_cat=101&ccb=1-7&_nc_sid=c53f8f&_nc_ohc=EWHzIxDAk20Q7kNvwFgPQrS&_nc_oc=AdmbvB4ypz9F2BrlQ7FcUMcvfR5JvoCggHJ1a4Ntu3ZXQ8KoiUCOTCYzvZ1z6gYiIJo&_nc_zt=14&_nc_ht=scontent-lga3-2.xx&_nc_gid=PBbgsjxhy8iorGrJjaavZw&oh=00_AfJd0SOIGy12aEqb4GS4Kz86YOdg3NpQ5OL9W-RRnBHPBQ&oe=6843A343",
"instagram_url": "",
"instagram_handle": "",
"is_reshared": false,
"version": 3,
"body": "Reflections ripple, light gathers,<br /> and tomorrow brings a new rhythm to the square. <br /> <br /> One day until the Grand Opening of Boka Place.",
"branded_content": {
"page_id": 166258896830103,
"page_name": "Porto Montenegro",
"page_profile_picture_url": "https://scontent-lga3-1.xx.fbcdn.net/v/t39.35426-6/499920502_2382687582132053_334434608727983440_n.jpg?_nc_cat=103&ccb=1-7&_nc_sid=c53f8f&_nc_ohc=zJEq2b_i4xwQ7kNvwEhuat_&_nc_oc=AdnryrPnSzR5YCB7wO-EVqpswUJ2l8xDDXiCjJN6b4rhZJ2c8809t5QTDa7OwUq9ueU&_nc_zt=14&_nc_ht=scontent-lga3-1.xx&_nc_gid=PBbgsjxhy8iorGrJjaavZw&oh=00_AfLZibsXYNxUNvp9LT4tOJWbf-3uFIkWN4e5ke-s5FqGdw&oe=68438B15",
"page_categories": {
"197251360301109": "Marina"
},
"current_page_name": "Porto Montenegro",
"page_profile_uri": "https://www.facebook.com/portomontenegrotivat/",
"page_is_deleted": false
},
"current_page_name": "Porto Montenegro Experience",
"page_like_count": 1,
"page_profile_uri": "https://www.facebook.com/61575286107814/",
"page_is_deleted": false,
"cta_type": "LEARN_MORE",
"instagram_branded_content": {
"instagram_bc_sponsor_id": "17841400741682419",
"instagram_bc_sponsor_name": "porto_montenegro"
}
},
"startDate": 1747897200,
"publisherPlatform": [
"facebook"
],
"totalActiveTime": 41782,
"url": "https://www.facebook.com/ads/library?id=702369045530963",
"startDateString": "2025-05-22T07:00:00.000Z",
"endDateString": "2025-05-23T07:00:00.000Z",
"aaa_info": {
"targets_eu": true,
"location_audience": [
{
"name": "Dubrovnik, Croatia",
"num_obfuscated": 0,
"type": "CITY",
"excluded": false
}
],
"gender_audience": "All",
"age_audience": {
"min": 18,
"max": 65
},
"eu_total_reach": 1657,
"age_country_gender_reach_breakdown": [
{
"country": "HR",
"age_gender_breakdowns": [
{
"age_range": "45-54",
"male": 101,
"female": 77,
"unknown": 4
}
]
}
],
"payer_beneficiary_data": [
{
"payer": "Porto Montenegro",
"beneficiary": "Porto Montenegro"
}
],
"has_violating_payer_beneficiary": false,
"is_ad_taken_down": false
}
}Best Practices
Error Handling
Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.
Caching
Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.
Security
Never expose your API key in client-side code. Use environment variables and secure key management practices.
Troubleshooting
Unauthorized
Check your API key is correct and properly formatted in the x-api-key header.
Payment Required
You ran out of credits and need to buy more.
Not Found
The resource (user, video, etc.) might not exist or be private.
Too Many Requests
You have exceeded your rate limit. Slow down your requests.
Frequently Asked Questions
How much does it cost to scrape Facebook Ad Library?
SociaVault offers 50 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.
Is it legal to scrape Facebook Ad Library data?
Scraping publicly available data is generally considered legal. We only collect public data that is accessible without logging in.
How fast can I scrape Facebook Ad Library?
Our API handles the rate limiting for you. You can make requests as fast as your plan allows.
What data format does the API return?
All API responses are returned in JSON format, making it easy to integrate with any programming language or application.
Related Tutorials
Ad Details in Other Languages
Ad Details with Node.jsAd Details with JavaScriptAd Details with PythonAd Details with PHPReady to Start Scraping?
Get started with 50 free API calls. No credit card required. Stop worrying about proxies and captchas.