Skip to content

@adamloving /fb-fan-export.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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;
// 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(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
Owner

Sign up for updates and instructions for this script here: http://adamloving.com/internet-programming/how-toexport-facebook-page-fans

There are currently two issues with this approach.

  1. If you are not the page administrator, you only get ~60% of the fans for any given page (presumably based on privacy settings).

  2. There seems to be a back end limit on 10,000 fans. In the script, after it requests 100 pages of 100, the same results set comes back for subsequent requests. I've tried different pages and page sizes. I've also tried using an offset parameter like the one documented with the graph API to no avail.

@adamloving
Owner

I've got two updates:

  1. Changes on Facebook's end broke the script because it couldn't identify the Profile ID number. I've updated the script to get it working again.

  2. It appears that Facebook no longer lets non-admins view a page's fans. So, this script now only works if you are the page admin.

@jhoonycode

I'm sorry but the system always tell me "Sorry couldn't find profile ID"
I try it on the fan page, on the administrator fan-page.
I need your help!
thks
G

@adamloving
Owner

jhoonycode - what browser are you using? I just tested it in Firefox 4 (with firebug), Safari, and Chrome. Only one it doesn't work in is Safari.

@jhoonycode

I'm using chrome!
I open my facebook page
open the administration panel
open the java console
and copy the code.

by the system return that don't find user ID.
what wrong?

@adamloving
Owner
@jhoonycode

I send you now an email with the HTML file.
I tried with the firefox and firebug too!
I need your help.
G

@Dwhitte

Script worked great out of Safari!
However it also exported a number and an http link to the person's profile. Is there a way to only export the name and not this secondary info?
Thanks.
Dave

@adamloving
Owner
@Dwhitte

Thank You. Worked great again.

@mc-b2d

Hi Forgive me - today still getting the profile id error when at the fan page i admin.

i get "Sorry couldn't find profile ID"

thoughts? and many thanks for the script

@mc-b2d

never mind... it seems to be running. wild. thanks a lot

@mc-b2d

now here's another quicky: is there any way to tell join date, or to anyone's knowledge, that data is just not captured?
again, great script. many thanks
mc

@refarc

Hi Adam,

I was also getting the "Sorry couldn't find profile ID" so I hacked your script and hard coded the page id which worked to certain extent. Essentially, the page has ~1640 fans but the script stopped at 1200. I signed in as admin. Any thoughts as to why the remaining 400 were not available?

BTW, the amended script is:

// start
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;
var nodeId = 123456;

// 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) {

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);

// end

@gmacgregor

"Essentially, the page has ~1640 fans but the script stopped at 1200. I signed in as admin. Any thoughts as to why the remaining 400 were not available?"

... change the value of endPage in the script above to something greater than 10.

@refarc
@adamloving
Owner

Thanks gmacgregor!

@leolambertini

Great work Adam, this worked like magic.

I'm wondering if you have found a workaround the 10, 000 user limit?

Thanx for sharing this

@adamloving
Owner
@jromanow

No description provided.

@jromanow

HELP! Adam, I can't get your script to work. I used Google Chrome and followed the steps above but go the "undefined" eror. I tried refarc's ammended script, and I got "Unexpected identifier" ......any ideas how I can fix???
You can reach me at: jromanow@bgeltd.com
Thanks - Jon

@adamloving
Owner
@breakaway11

Worked awesome for me with 632 fans.... this will make it much easier to find a winner for my giveaway contest for my facebook fans.

@lawpa

Sorry for the newbie comment here. This is what I've done in Safari. Let me know if I'm on the right path or way off.

I've clicked "Develop" in Safari. Then "Start Profiling Javascript". Then clicked on "Consol". Pasted the code. Changed the word ('meta') to (my id number). Then at the end of the code press enter.

Thanks for the help!

@lawpa

I think I'm actually stuck at where to put the Profile ID in the script. Please help. Thanks

@adamloving
Owner

lawpa - change

var nodeId = getNodeId();

to

var nodeId = PROFILEID;

where PROFILEID is your id number. hope that helps...

@lawpa

Worked like a charm! Thanks!!!

@adamloving
Owner
@bobalouie

This worked perfectly Adam! All I had to do was put in my FB Page ProfileID into the correct location (as you instructed Iawpa above) and voila! Thank you so much!

@jromanow
@pedromiravaz

Hi,

Looks real nice. Used it to great satisfaction.
Still, the 10,000 is problem for me, cause I have around 17,000. Do you think you can pass a filter to the listing you're doing, and retrieve a, then b, etc?

Best regards.

@taneleero

Super script Adamloving, worked like a charm and I got all my 4280 fans exported. Love that I can simply edit what components are exported and then its just a few clicks to get all that into excel for some sorting :).

This would be perfect if you could find a workaround for the 10k limit. I found this from Google and this looks to be one of the simplest and easyest way to export fan lists.

Again, thanks a million!

@dbgarris

Great script Adam!!! I am having intermittent problems and was wondering if others are seeing the same. I too see “undefined” after I execute the script but still the script executes properly sometimes. I haven’t been able to figure out why it doesn’t execute each time…sometimes I have to attempt to run the script for many times for several days before I get any results. Any ideas? I am using XP sp2 and google chrome.

@dbgarris

I also forgot to mention that I am running the script on a sports venue page to which I am an admin

@dbgarris

I really need to get this script working again. Is there any possible way to debug it?

@rjmcleod

Thanks for this Adam! I've been looking for something like this for 3 weeks. Phew!

@AaronSachs

Is there a way to get emails, like if I wanted to compile them for a monthly email database?

@adamloving
Owner
@grahamh

i had the same problem with unable to get the profile id. I solved it by switching my account so that I was using facebook as my fan page, not as my normal user. If you are an administrator then you get an option to use facebook as "your page name". Clicking on this and then running the script worked.

Thanks very much for a great script.

@idashi

Thanks so much for this awesome script! Worked perfectly and saved me a ton of time!

@mdchang

Hi! Is there a way for the list to show up in signup order? Ie: fans that have been with me the longest at one end and newest fans at the other?

@adamloving
Owner
@myredm6

Hi Adam,
I am also getting the error with the Profile ID. I am using Chrome and I am logged into FB as the business admin and still I get an error. Does this script still work or do I need to do something more with the ProfileID that I am not understanding. Thanks so much

Crystal
myredm6@yahoo.com

@myredm6

I got the code to work. This is definitely a newby question - so sorry - but how do I export the information. It does not let me highlight to copy and paste the info.

@bigchain

I loaded the facebook page, logged in as admin copied the code inside scripts, but nothing in console, not sure if I;m missing something Thnks guys

@adamloving
Owner

Hi - I just tested this again tonight to make sure that it is working. Worked for me first try. I'm using Chrome on Mac (Lion). If it doesn't work for you, please post what browser and OS you are using.

@russellunidad

hi adam,

i just tried using your code and followed the instructions (im in the facebook fan page, and im an administrator) in the email i received, but i am getting a "Sorry couldn't find profile ID", im very noob in backend programming, i just copy pasted your code you put here, is there anything that i need to replace on your code? and if ever where can i put the replacement? by the way here is the code i copied along with the comments. - thanks

/*

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(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
Owner
@adamloving
Owner
@davidlano

How would I go about getting the first name and last name separated by a comma? I know the userData.title gets the full name...but I'm not sure how to get each independently. Any ideas? Thanks!

@loskurva

Hello Adam,
I love the code, and cut out the profile link part. I had a question for you though. How do I (if it's possible) get the email address associated with the fan's profile? eg, I tried userData.email but it didnt work. Thank you

@vladakilov

This works perfectly for me however, I would like to implement this on a standalone page not just run it through firebug or js consoles of various browsers. I've been trying to implement this on a facebook app with no luck because of cross domain requests issues due to facebook apps being iframes within facebook but actually hosted on another domain.
Btw this code works for sites that I'm not even an admin of, so long as I have the correct page id. I also noticed that you don't need post_form_id or fb_dtsg values in the data dict.

@phamdlt

Hi Adam,
Thank you so much for the code. I was wondering if there was a way to pull out just a fan's college education.

Thank you

@tripleonard

Thanks for this Adam! Here are some Chrome tips:

  1. For the "Sorry couldn't find profile ID" - I found that I had to close all Chrome tabs, open a new window/tab, navigate to fb page, then run your script. It works!

  2. If, after you run script, you navigate away from the javascript console (to another website for example) OR try to select/copy from the bottom of the output page, it will not let you highlight the output (see myredm6 above).

Hope this helps other.

@adamloving
Owner
@brrobbins

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

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
Owner
@cavi21

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

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

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
Owner

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

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

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

@sackling

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

@aubreyt2

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

@oozemund

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.

@gituserhub

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

@adamloving
Owner
@Shachary

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

I try this script and take the same error above.

What can I do?

@angisingh

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

Same question?Does this script still work?

@adamloving
Owner
@BugsyMcgraw

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

@DMTarmey

I Get Uncaught SyntaxError: Unexpected token *

@DMTarmey

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.