Last active
February 21, 2023 10:24
-
-
Save dvygolov/e61d28fc283990aa7107f20878da866b to your computer and use it in GitHub Desktop.
Import users to the Blocked list of a Facebooks Fan Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let api = 'https://graph.facebook.com/v14.0'; | |
let headers = { | |
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | |
"accept-language": "en-US,en;q=0.9", | |
"cache-control": "max-age=0", | |
"sec-ch-ua": "\"Google Chrome\";v=\"107\", \"Chromium\";v=\"107\", \"Not=A?Brand\";v=\"24\"", | |
"sec-ch-ua-mobile": "?0", | |
"sec-ch-ua-platform": "\"Windows\"", | |
"sec-fetch-dest": "document", | |
"sec-fetch-mode": "navigate", | |
"sec-fetch-site": "none", | |
"sec-fetch-user": "?1", | |
"upgrade-insecure-requests": "1" | |
}; | |
let f = await fetch(`${api}/me/accounts?access_token=${__accessToken}`, { | |
"headers": headers, | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": null, | |
"method": "GET", | |
"mode": "cors", | |
"credentials": "include" | |
}); | |
let js = await f.json(); | |
let data = js['data']; | |
let msg = ''; | |
for (let i = 0; i < data.length; i ++) { | |
msg += `${i+1}. ${data[i]['name']}\n`; | |
} | |
let fpIndex = prompt(`Choose your FanPage (for example, 1):\n${msg}`); | |
let fp = data[fpIndex-1]; | |
let fpId = fp['id']; | |
let usersText=prompt(`${fp['name']} selected!\nEnter user ids to block (divided by Enter):`); | |
let users = usersText.split('\n'); | |
var userIds=[]; | |
let r = /\d+/; | |
for (var i=0;i<users.length;i++){ | |
userIds.push(r.exec(users[i])[0]); | |
} | |
console.log(`Total users found:${users.length}`); | |
let result = await blockUsers(fpId,fp['access_token'],userIds); | |
alert(JSON.stringify(result)); | |
async function blockUsers(fpId,fpToken,users){ | |
let f = await fetch(`${api}/${fpId}/blocked?access_token=${fpToken}&method=post&user=${JSON.stringify(users)}`, { | |
"headers": headers, | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": null, | |
"method": "GET", | |
"mode": "cors", | |
"credentials": "include" | |
}); | |
let js = await f.json(); | |
console.log(js); | |
return js; | |
} |
Sadly an error occured. How can I fix that?
Access to fetch at 'https://graph.facebook.com/v14.0/113326078349815/blocked?access_token=EAABsbCS1iHgBABYpc54FIo5iZAZAnbMRQHLqyHVCUbnVNrRdfQVfq24OBumXliwxm7AM4HvQH1wDPPQezXZBMnihbmGELziCh5dTOjLm8lfgrgi8u0ZBSf6ZAcgwtMjo2HnoneXwWSfnj6qsANZCVIW6aN6F3CyzCVGrFUR80IFT31DZAbk3uzxOSIDsQZDZD&method=post&user=[%22100006392290962%22]' from origin 'https://business.facebook.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
just change business.facebook.com to www.facebook.com in your url and you
are good to go!
…On Tue, Feb 21, 2023 at 1:56 PM veinsis ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Sadly an error occured. How can I fix that?
Access to fetch at '
https://graph.facebook.com/v14.0/113326078349815/blocked?access_token=EAABsbCS1iHgBABYpc54FIo5iZAZAnbMRQHLqyHVCUbnVNrRdfQVfq24OBumXliwxm7AM4HvQH1wDPPQezXZBMnihbmGELziCh5dTOjLm8lfgrgi8u0ZBSf6ZAcgwtMjo2HnoneXwWSfnj6qsANZCVIW6aN6F3CyzCVGrFUR80IFT31DZAbk3uzxOSIDsQZDZD&method=post&user=[%22100006392290962%22]
<https://graph.facebook.com/v14.0/113326078349815/blocked?access_token=EAABsbCS1iHgBABYpc54FIo5iZAZAnbMRQHLqyHVCUbnVNrRdfQVfq24OBumXliwxm7AM4HvQH1wDPPQezXZBMnihbmGELziCh5dTOjLm8lfgrgi8u0ZBSf6ZAcgwtMjo2HnoneXwWSfnj6qsANZCVIW6aN6F3CyzCVGrFUR80IFT31DZAbk3uzxOSIDsQZDZD&method=post&user=%5B%22100006392290962%22%5D>'
from origin 'https://business.facebook.com' has been blocked by CORS
policy: Response to preflight request doesn't pass access control check:
The value of the 'Access-Control-Allow-Origin' header in the response must
not be the wildcard '*' when the request's credentials mode is 'include'.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/e61d28fc283990aa7107f20878da866b#gistcomment-4478005>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACGSGCL7MJY6MMHSFOWYB2DWYSGLTBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTANZVGAYTMNZTU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Still don't work. Am I doing right by run it in ads manager?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome! Thank you so much