use reqwest;
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let result = scrape().await?;
println!("Response: {}", result);
Ok(())
}
async fn scrape() -> Result<String, Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
// Build query parameters
let mut params = HashMap::new();
params.insert("query".to_string(), "running".to_string());
params.insert("sort_by".to_string(), "total_impressions".to_string());
params.insert("search_type".to_string(), "keyword_unordered".to_string());
params.insert("ad_type".to_string(), "all".to_string());
params.insert("country".to_string(), "ALL".to_string());
params.insert("language".to_string(), "EN".to_string());
params.insert("status".to_string(), "ACTIVE".to_string());
params.insert("media_type".to_string(), "ALL".to_string());
params.insert("start_date".to_string(), "2025-01-05".to_string());
params.insert("end_date".to_string(), "2025-02-16".to_string());
params.insert("cursor".to_string(), "AQHRYLVDkoMkvGv7yK1rcce-vJmKiKv330R4v3j9KHSOaYvmF1bq1QkotG0rgW8Fkrj-".to_string());
params.insert("trim".to_string(), "false".to_string());
let response = client
.get("https://api.scrapecreators.com/v1/facebook/adLibrary/search/ads")
.header("x-api-key", "YOUR_API_KEY")
.header("Content-Type", "application/json")
.query(¶ms)
.send()
.await?;
if response.status().is_success() {
let body = response.text().await?;
Ok(body)
} else {
Err(format!("HTTP {}: {}", response.status(), response.text().await?).into())
}
}