Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export Facebook Page Fans
/*
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 = 10; // change this if you have more than 1,000 fans
// Find the social graph node ID (page profile ID) by peeking at meta tags
var getNodeId = function() {
var metaTags = document.getElementsByTagName('meta');
for (i in metaTags) {
var tag = metaTags[i];
if (tag.content && tag.content.match(/_([0-9]+)_/)) {
return tag.content.match(/_([0-9]+)_/)[1];
}
}
return null;
}
// 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('http://www.facebook.com/profile.php?id=' + 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 nodeId = getNodeId();
if (!nodeId) {
alert('Sorry couldn\'t find profile ID');
return;
}
var data = {
edge_type: 'fan',
page: page,
limit: usersPerPage,
node_id: nodeId,
'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);
@adamloving
Copy link
Author

adamloving commented Sep 22, 2011

@brrobbins
Copy link

brrobbins commented Sep 23, 2011

I got the list of names of fans using your instructions, but didn't capture email addresses from fans ... is there a way to get the email addresses along with this list of names?

@amorame
Copy link

amorame commented Sep 27, 2011

Hey Adam,
I've tried again and again to get this work.. However, I keep encountering the same error messeage -
''POST http://www.facebook.com/ajax/social_graph/fetch.php?__a=1 500 (Internal Server Error)''
Could you kindly advise what I might be doingg wrong here as I see it has worked for others?
Many thanks!!

@adamloving
Copy link
Author

adamloving commented Sep 27, 2011

@cavi21
Copy link

cavi21 commented Sep 27, 2011

Adam, this works great the only problem now is that facebook does not put the email in the e.payload.user_info anymore, do you know where we could find that info? because y check in the objects and seems i couldn't find it!

Thanks a lot
Agustin

@aclement84
Copy link

aclement84 commented Oct 12, 2011

Hi Adam, Thanks for sharing!

This worked great for a few weeks and I was really excited! Today, though, I got this error message...

POST http://www.facebook.com/ajax/social_graph/fetch.php?__a=1 404 (Not Found)

Any idea what is going on or how to fix it? Thanks!

Andrew

@jbean1
Copy link

jbean1 commented Oct 13, 2011

I've been using this successfully for the past few weeks as well (thank you!) but this morning I'm getting the same message Andrew is.

POST http://www.facebook.com/ajax/social_graph/fetch.php?__a=1 404 (Not Found)

Jill

@adamloving
Copy link
Author

adamloving commented Oct 13, 2011

Facebook updated their site yesterday, so the script above no longer works. I've re-written the script to scrape the fans from DOM nodes instead of using the Facebook AJAX libraries. For the moment, I'm only supplying the latest version to those that paid for the premium version in the past. I'll post here when I make it available again. Thanks!

@djw81580
Copy link

djw81580 commented Oct 14, 2011

Hey Man,
I am new to this and just tried pasting the script in my console. No emails have popped up yet. What am I doing wrong?

@djw81580
Copy link

djw81580 commented Oct 14, 2011

you can reach me at djw81580@gmail.com
Thanks dude for your great work!! you are helping alot of people!!

@sackling
Copy link

sackling commented Oct 27, 2011

Hey I'd be very interested in that script! Never got to try the original.

@aubreyt2
Copy link

aubreyt2 commented Oct 27, 2011

I'd love to pay to get the new version! Need to run this script for work! Thanks so much!

@oozemund
Copy link

oozemund commented Oct 28, 2011

I can't stress enough how a lot of people would be willing to pay for the new script. It seems a strange way to supply the latest version only to people who've bought the old version.

@filip-rufer
Copy link

filip-rufer commented Nov 2, 2011

Hi adamloving, would it be somehow possilble to buy the new script from you? Thanks!

@adamloving
Copy link
Author

adamloving commented Nov 8, 2011

@Shachary
Copy link

Shachary commented Nov 27, 2011

Hi guys,

I'm trying to get the info from my fan page. I use Chrome and i'm an admin of the page.
I've changed the var nodeId to my profile ID. I still get this error:

POST https://www.facebook.com/ajax/social_graph/fetch.php?__a=1 404 (Not Found)

Any clue???

Thanks

@lucasoliveira3
Copy link

lucasoliveira3 commented Dec 6, 2011

I try this script and take the same error above.

What can I do?

@angisingh
Copy link

angisingh commented Jan 12, 2012

Does this script still work. I noticed that the AJAX call on the FB insights tab when I request the Likes has changed. I tried running the script with a few modifications like the uri etc but the payload coming back is null

@sarowar
Copy link

sarowar commented Jan 24, 2012

Same question?Does this script still work?

@adamloving
Copy link
Author

adamloving commented Jan 24, 2012

@BugsyMcgraw
Copy link

BugsyMcgraw commented Jun 25, 2014

Hey guys, any update on this? Has it started working again? Can it still work as at now?

@dediwalage
Copy link

dediwalage commented Jul 1, 2014

@DMTarmey
Copy link

DMTarmey commented Jan 15, 2015

I Get Uncaught SyntaxError: Unexpected token *

@DMTarmey
Copy link

DMTarmey commented Jan 15, 2015

Tried gain and got
Uncaught TypeError: Cannot read property 'value' of null
K67qezNkvZQ.js:125 GET https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-xpa1/t39.2365-6/851572_598595820234442_132828333_n.jpg net::ERR_NAME_NOT_RESOLVED

@moss123456
Copy link

moss123456 commented Feb 23, 2016

@adamloving and other programmers.

Hi

How do I gather ID's of PAGES, not the USERS on a page.

Example: I want to gather all ID’s of PAGES that contain the

Search keyword “XYZ” to message the PAGE ADMINISTRATOR.

If a brand has 1000+ facebook pages, then I would like to gather the ID’s of the brands pages.

I simply cannot find a solution online, nor can figure our whether your software can achieve this result.’

Many thanks
moss.27@hotmail.com

@sandeepmondal
Copy link

sandeepmondal commented Sep 14, 2017

Hi adamloving ,

Fetching Pages fans detail is possible now a days ??

@rudolphos
Copy link

rudolphos commented Nov 19, 2017

Is there gonna be any other update to this?

@gusbemacbe
Copy link

gusbemacbe commented Mar 18, 2019

Too bad that I can not extract the list of a page fans as non-administrator for blacklisting them from accessing my another page.

@rodalvi
Copy link

rodalvi commented Jun 27, 2020

Is there something that is not expired?

@Danie11111
Copy link

Danie11111 commented Dec 3, 2021

Do you know that you can use an easier way? There’s excellent software Cucomm that copes with such tasks. The software collects fb profiles, adds them to friends and automatically sends messages. At the same time, you don’t need to enter your password, and there’s no chance of being blocked. Advice u to try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment