Skip to content

Instantly share code, notes, and snippets.

@dvygolov
Last active November 12, 2024 13:40
Show Gist options
  • Save dvygolov/14c2fbd9700b02aa5720986a846850b2 to your computer and use it in GitHub Desktop.
Save dvygolov/14c2fbd9700b02aa5720986a846850b2 to your computer and use it in GitHub Desktop.
Simple request that shows how to get results from Facebook Ads Library
var session_id = self.crypto.randomUUID();
var lsd = require("LSD").token;
var dtsg = require("DTSGInitialData").token;
var uid = require("CurrentUserInitialData").USER_ID;
var params = {
"q":"loose weight",
"countries[0]":"US",
"count":30,
"session_id":session_id,
"active_status":"all",
"ad_type":"all",
"media_type":"all",
"search_type":"keyword_unordered"
};
var qs = new URLSearchParams(params).toString();
var url = `https://www.facebook.com/ads/library/async/search_ads/?${qs}`;
var f = await fetch(url, {
"credentials": "include",
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 YellowWeb",
"Accept": "*/*",
"Accept-Language": "ru,en-US;q=0.7,en;q=0.3",
"Content-Type": "application/x-www-form-urlencoded",
"X-FB-LSD": lsd,
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
},
"body": `__user=${uid}&__a=1&fb_dtsg=${dtsg}&lsd=${lsd}`,
"method": "POST",
"mode": "cors"
});
var resp = await f.text();
console.log(resp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment