Created
December 27, 2018 02:32
-
-
Save monokaijs/e3a0ecd51ef762433a9462d673f64270 to your computer and use it in GitHub Desktop.
Set all Facebook Posts on Timeline with a specified Privacy value.
This file contains hidden or 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
(() => { | |
/* | |
{ | |
author: 'MonokaiJs', | |
facebook: 'https://fb.me/MonokaiJsp', | |
homepage: 'https://omfg.vn' | |
// Please DO NOT REMOVE CREDITS IN THIS FILE. | |
} | |
*/ | |
var privacy = "SELF"; /*EVERYONE, ALL_FRIENDS, FRIENDS_OF_FRIENDS, SELF, CUSTOM*/ | |
var get_token = (callback) => {var uid = document.cookie.match(/c_user=(\d+)/)[1],dtsg = document.getElementsByName("fb_dtsg")[0].value,http = new XMLHttpRequest,url = "//www.facebook.com/v1.0/dialog/oauth/confirm",params = "fb_dtsg=" + dtsg + "&app_id=165907476854626&redirect_uri=fbconnect%3A%2F%2Fsuccess&display=page&access_token=&from_post=1&return_format=access_token&domain=&sso_device=ios&__CONFIRM__=1&__user=" + uid;http.open("POST", url, !0), http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), http.onreadystatechange = function() {if (4 == http.readyState && 200 == http.status) {var a = http.responseText.match(/access_token=(.*)(?=&expires_in)/);a = a ? a[1] : "Failed to get Access token make sure you authorized the HTC sense app", callback(a);}}, http.send(params);} | |
get_token((token) => { | |
var r = new XMLHttpRequest; | |
r.onreadystatechange = () => { | |
if (r.readyState == 4 && r.status == 200) { | |
var posts = JSON.parse(r.responseText).data; | |
posts.forEach(post => { | |
var s = new XMLHttpRequest; | |
s.onreadystatechange = () => { | |
if (s.readyState == 4) { | |
if (s.status == 200) { | |
console.log('Post [' + post.id + '].privacy is set to ' + privacy); | |
} else { | |
console.log('Failed to set [' + post.id + '].privacy'); | |
} | |
} | |
} | |
s.open('GET', 'https://graph.facebook.com/' + post.id + "?method=POST&privacy={'value':'"+privacy+"'}&access_token=" + token); | |
s.send(); | |
}); | |
} | |
} | |
r.open('GET', 'https://graph.facebook.com/me/feed?fields=id&limit=5000&access_token='+token); | |
r.send(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment