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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still don't work. Am I doing right by run it in ads manager?