public
Created — forked from adamloving/fb-fan-export.js

Export Facebook Page Fans

  • Download Gist
fb-fan-export.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
/*
 
For more detailed instructions on how to use this script, sign up with your email here:
http://adamloving.com/internet-programming/how-toexport-facebook-page-fans
 
DISCLOSURE: This javascript runs in your browser pretending to be you
looking through your page fans. Facebook should have no problem with this,
but who knows if they will think it is strange to see you looking through
all your fans so quickly (the script waits 3s before requesting each page).
I've had no problem running this so far for 1000s of page fans, but I
cannot be held liable if your Facebook account gets banned or your page
gets disabled for any reason for using this script.
 
INSTRUCTIONS:
 
1. Download Google Chrome Web browser (or Apple Safari)
 
2. Enable the developer tools
 
3. Open the javascript console and cut and paste the attached script into the console.
 
The script will fetch users 100 at a time and output the results into the console which you can then cut and paste into a CSV file.
 
*/
 
var uri = '/ajax/social_graph/fetch.php?__a=1';
var lastResponse = null;
var usersPerPage = 100;
var totalUsersDownloaded = 0;
var throttle = 3000; // how long to wait between pages
var startPage = 0
var endPage = 100;
 
// Find the social graph node ID (page profile ID) by peeking at some UI configuration data
var getNodeId = function() {
for (key in window.__UIControllerRegistry) {
var pagelet = window.__UIControllerRegistry[key];
if (pagelet._context_data && pagelet._context_data.profile_id)
return pagelet._context_data.profile_id;
}
}
 
// Process the AJAX call response and dump the user data to the console
var OnResponse = function(e) {
console.log('--- Page: ' + e.payload.page);
lastResponse = e; // for debugging
for (userId in e.payload.user_info) {
var userData = e.payload.user_info[userId];
totalUsersDownloaded++;
console.log(userId + ',' + userData.title + ',' + userData.subtitle + ',' + userData.pic)
}
console.log('Downloaded: ' + totalUsersDownloaded + ' of ' + e.payload.count)
if (e.payload.page <= endPage && totalUsersDownloaded < e.payload.count) {
setTimeout(function() { downloadUsers(e.payload.page + 1); }, 3000);
}
}
 
// Make an AJAX call for the data using FB's AJAX library
var downloadUsers = function(page) {
var data = {
edge_type: 'fan',
page: page,
limit: usersPerPage,
node_id: getNodeId(),
class: 'FanManager',
post_form_id: document.getElementById('post_form_id').value,
fb_dtsg: document.getElementsByName('fb_dtsg')[0].value,
lsd: null,
post_form_id_source: 'AsyncRequest'
}
 
var req = new AsyncRequest()
.setURI(new URI(uri))
.setMethod('POST')
.setData(data)
.setHandler(OnResponse);
 
result = req.send();
}
 
downloadUsers(startPage);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.