72

I'd like to get a list of users who like a certain page or a fan of it.

The FB API documentation states that you can only get the count of the fans of a certain page using the social graph, but not a list of the fans.

A discussion here Retrieve Facebook Fan Names suggests that one could use an FQL query like SELECT user_id FROM like WHERE object_id="YOUR PAGE ID" to get the number of people who liked the page, but for the same page, it gives an empty response "{}".

So I was wondering if anyone has an idea if this can be done.

Community
  • 1
  • 1
pesho
  • 1,232
  • 2
  • 13
  • 11
  • You can only get the fans of pages that you are an administrator for. So you have to provide an access token with your request associated with an admin account of the page you are trying to get the fans. – Nate Totten Oct 26 '10 at 04:00
  • 3
    how? 2 years later I still don't see a way? – Dmitry B. Aug 03 '12 at 16:28
  • I upvoted this just to give you 69th vote :D –  Aug 11 '18 at 11:47

8 Answers8

70

There is a "way" to get some part of fan list with their profile ids of some fanpage without token.

  1. Get id of a fanpage with public graph data: http://graph.facebook.com/cocacola - Coca-Cola has 40796308305. UPDATE 2016.04.30: Facebook now requires access token to get page_id through graph so you can parse fanpage HTML syntax to get this id without any authorization from https://www.facebook.com/{PAGENAME} as in example below based on og tags present on the fanpage.
  2. Get Coca-Cola's "like plugin" iframe display directly with some modified params: http://www.facebook.com/plugins/fan.php?connections=100&id=40796308305
  3. Now check the page sources, there are a lot of fans with links to their profiles, where you can find their profile ids or nicknames like: http://www.facebook.com/michal.semeniuk .
  4. If you are interested only in profile ids use the graph api again - it will give you profile id directly: http://graph.facebook.com/michal.semeniuk UPDATE 2016.04.30: Facebook now requires access token to get such info. You can parse profile HTML syntax, just like in the first step meta tag is your best friend: <meta property="al:android:url" content="fb://profile/{PROFILE_ID}" />

And now is the best part: try to refresh (F5) the link in point 2.. There is a new full set of another fans of Coca-Cola. Take only uniques and you will be able to get some nice, almost full list of fans.

-- UPDATE 2013.08.06 --

Why don't you use my ready PHP script to fetch some fans? :)

UPDATE 2016.04.30: Updated example script to use new methods after Facebook started to require access token to get public data from graph api.

function fetch_fb_fans($fanpage_name, $no_of_retries = 10, $pause = 500000 /* 500ms */){
    $ret = array();
    // prepare real like user agent and accept headers
    $context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-encoding: gzip, deflate, sdch\r\nAccept-language: en-US,en;q=0.8,pl;q=0.6\r\n')));
    // get page id from facebook html og tags for mobile apps
    $fanpage_html = file_get_contents('https://www.facebook.com/' . $fanpage_name, false, $context);
    if(!preg_match('{fb://page/(\d+)}', $fanpage_html, $id_matches)){
        // invalid fanpage name
        return $ret;
    }
    $url = 'http://www.facebook.com/plugins/fan.php?connections=100&id=' . $id_matches[1];
    for($a = 0; $a < $no_of_retries; $a++){
        $like_html = file_get_contents($url, false, $context);
        preg_match_all('{href="https?://www\.facebook\.com/([a-zA-Z0-9\._-]+)" class="link" data-jsid="anchor" target="_blank"}', $like_html, $matches);
        if(empty($matches[1])){
            // failed to fetch any fans - convert returning array, cause it might be not empty
            return array_keys($ret);
        }else{
            // merge profiles as array keys so they will stay unique
            $ret = array_merge($ret, array_flip($matches[1]));
        }
        // don't get banned as flooder
        usleep($pause);
    }
    return array_keys($ret);
}

print_r(fetch_fb_fans('TigerPolska', 2, 400000));
Chris Tanner
  • 90
  • 1
  • 6
s3m3n
  • 4,187
  • 1
  • 28
  • 24
  • 2
    How to get it through Graph api or fql ? I guess there is no way we can get profile name who liked the page. – Sanket Jul 11 '12 at 05:43
  • Where did you find out about this like plugin ? – James P. Sep 29 '12 at 04:23
  • 1
    @JamesPoulson it's official FB like plugin to embed on external webpages, there is even generator: https://developers.facebook.com/docs/reference/plugins/like-box/ – s3m3n Oct 25 '12 at 15:26
  • http://www.facebook.com/plugins/fan.php?connections=100&id=40796308305 i think they set the limit to 100 instead of allowing to grab 10000 users at a time... – Matical Mar 31 '13 at 23:00
  • Why don't you try my ready php script for fetching fb fans without authorization? – s3m3n Aug 05 '13 at 23:33
  • Your script is very interesting but does it not violate the FB TOS? – High schooler Aug 24 '13 at 20:31
  • @KingofGames not sure about it. Stackoverflow examples are for education purposes, I'm not using this script on my production servers so I haven't checked TOS. – s3m3n Aug 26 '13 at 09:29
  • Looks like the selection of people who appear in the facepile isn't truly random anymore. – Hayko Koryun Oct 14 '13 at 10:13
  • I have a page with 56 likes, when running your script it only returns 21, I need to grab all 56 users, and I don't know why it would not show them all. When opening fan.php page it show everyone, even in incognito mode, but your php script don't. Any thoughts? – Marcel Dec 06 '13 at 15:24
  • No need to use the graph api. Profile id has already existed in the small profile image path. – redice Dec 21 '13 at 11:34
  • so is this legal according to facebook TOS? – JohnnyM Jan 24 '14 at 14:28
  • for some reason the maximum amount of **unique** fans is limited to 214. this is from a bank of 15470 fans. the percentage does not appear to be a whole number. I have mined the fan page 1000 times, producing 100000 fans (expecting to get somewhere close to 15000 uniques), but of those only 214 are unique. I wonder why this is? – pulsar Mar 25 '14 at 12:22
  • I just repeated the process for Coca Cola and out of 100000 fans only 367 were unique. whatever is going on at Facebook's end, this is a pretty useless ratio. – pulsar Mar 25 '14 at 12:50
  • I just tried your script. It doesn't work the empty matches is always. True. – user1007522 May 18 '14 at 12:27
  • You are right, FB changed default url to user profile, now it starts with `https` protocol instead of `http`. Updated my answer to fetch both protocols and it works again. – s3m3n May 18 '14 at 22:49
  • you will not get likers if their privacy setting is set to friends of mine or private even if you are admin of the page. with this method you will only get public likes. (same problem if you login to fb with admin account you wont get likers if security level is set to friends. you should be friend of the liker to see the info, being admin of the page is not enough. In the past it was possible, admin could see all likes even private) – benchpresser Oct 23 '14 at 07:44
  • Function kept returning `file_get_contents(http://graph.facebook.com/cindypizzaplace): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request` – code-8 Jan 21 '16 at 20:33
  • Function kept returning file_get_contents(http://graph.facebook.com/cindypizzaplace): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request – Mohammad Sadiq Apr 29 '16 at 11:56
  • Thanks, updated the answer with new solution. FB now requires access token to get anything from Graph API. – s3m3n Apr 30 '16 at 20:20
  • Where do you use graph api in your code? I dont see any. – Noah Oct 29 '16 at 11:17
  • I get only 1 to 6 results. No more :( – Portekoi Sep 14 '17 at 10:33
41

You can get fans using new facebook search: https://www.facebook.com/search/321770180859/likers?ref=about

Oleg
  • 7,070
  • 4
  • 47
  • 49
10

Use this.

https://www.facebook.com/browse/?type=page_fans&page_id=<your page id>

It will return up to 500 of the most recent likes.

http://www.facebook.com/browse/?type=page_fans&page_id=<your page id>&start=400

Each page will give you 100 fans. Change start value to (0, 100, 200, 300, 400) to get the first 500. If start is >= 401, the page will be blank :(

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
6

According to the Facebook documentation it's not possible to get all the fans of a page:

Although you can't get a list of all the fans of a Facebook Page, you can find out whether a specific person has liked a Page.

Steven Delrue
  • 423
  • 5
  • 8
3

For s3m3n's answer, Facebook fans plugin (e.g. LAMODA) has limitation now, you get less and less new fans on continuous requests. You may try my modified PHP script to visualize results: https://gist.github.com/liruqi/7f425bd570fa8a7c73be#file-facebook_fans_by_plugin-php

Another approach is Facebook graph search. On search result page: People who like pages named "Lamoda" , open Chrome console and run JavaScript:

var run = 0;
var mails = {}
total = 3000; //滚动次数,可以自己根据情况定义

function getEmails (cont) {
    var friendbutton=cont.getElementsByClassName("_ohe");
    for(var i=0; i<friendbutton.length; i++) {
        var link = friendbutton[i].getAttribute("href");

        if(link && link.substr(0,25)=="https://www.facebook.com/") {
            var parser = document.createElement('a');
            parser.href = link;
            if (parser.pathname) {
                path = parser.pathname.substr(1);
                if (path == "profile.php") {
                    search = parser.search.substr(1);
                    var args = search.split('&');
                    email = args[0].split('=')[1] + "@facebook.com\n";
                } else {
                    email = parser.pathname.substr(1) + "@facebook.com\n";
                }
                if (mails[email] > 0) {
                    continue;
                }
                mails[email] = 1;
                console.log(email);
            }
        }
    }
}

function moreScroll() {
    var text="";
    containerID = "BrowseResultsContainer"
    if (run > 0) {
        containerID = "fbBrowseScrollingPagerContainer" + (run-1);
    }
    var cont = document.getElementById(containerID);
    if (cont) {
        run++;
        var id = run - 2;
        if (id >= 0) {
            setTimeout(function() {
                containerID = "fbBrowseScrollingPagerContainer" + (id);
                var delcont = document.getElementById(containerID);
                if (delcont) {
                getEmails(delcont);
                delcont.parentNode.removeChild(delcont);
                }
                window.scrollTo(0, document.body.scrollHeight - 10);
            }, 1000);
        }
    } else {
        console.log("# " + containerID);
    }
    if (run < total) {
        window.scrollTo(0, document.body.scrollHeight + 10);
    }
    setTimeout(moreScroll, 2000);
}//1000为间隔时间,也可以根据情况定义

moreScroll();

It would load new fans and print user id/email, remove old DOM nodes to avoid page crash. You may find this script here

liruqi
  • 1,524
  • 15
  • 12
1

This page https://developers.facebook.com/docs/reference/fql/like/ wrote, you can't get fan list.

"The Post, Video, Note, Link, Photo and Album Graph API objects contain an equivalent connection called likes."

NOTE: fql like query is deprecated

Murat Kucukosman
  • 634
  • 5
  • 11
0

Technically this FQL query should work, but for some reason Facebook disallows it because of a missing index. Not sure if that is because of policy or they just forgot.

SELECT uid FROM page_fans WHERE page_id="YOUR_PAGE_ID"
Robin Smidsrød
  • 447
  • 4
  • 9
0

I created small tool called luster for downloading list of "likers" and "followers" of your Facebook page.

After download and unpack archive for your platform you can run it from terminal as

luster fans my-page-name

Where my-page-name is string identifier of your Facebook page.

You will be asked for email and password to your Facebook account. Note that this account need to have one of available page roles. Even Analyst is enough.

After while you should receive output similar to following

TIME,KIND,ID,NAME,LINK
1581665652,Like,111111111,John Doe,https://www.facebook.com/111111111
1581663355,Like,222222222,Kal Peterson,https://www.facebook.com/222222222
1581661970,Follow,333333333,Nikol Kus,https://www.facebook.com/333333333

This tool is based on reading table which can be found in Settings -> People and Other Pages section of your Facebook page.

Be aware that there is some limit up to 7k results from Facebook side. I tested it on two pages with more than 20k of fans and didn't get more then 7k results.

See https://github.com/zladovan/luster for details.

Ján Čabala
  • 184
  • 1
  • 7