Facebook API: Get fans of / people who like a page
Asked Answered
B

8

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.

Borehole answered 25/10, 2010 at 21:4 Comment(3)
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.Pheni
how? 2 years later I still don't see a way?Shugart
I upvoted this just to give you 69th vote :DAnticholinergic
I
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));
Invidious answered 5/6, 2012 at 23:22 Comment(21)
How to get it through Graph api or fql ? I guess there is no way we can get profile name who liked the page.Smoothie
Where did you find out about this like plugin ?Cataphyll
@JamesPoulson it's official FB like plugin to embed on external webpages, there is even generator: developers.facebook.com/docs/reference/plugins/like-boxInvidious
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...Protostele
Why don't you try my ready php script for fetching fb fans without authorization?Invidious
Your script is very interesting but does it not violate the FB TOS?Without
@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.Invidious
Looks like the selection of people who appear in the facepile isn't truly random anymore.Hindu
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?Niagara
No need to use the graph api. Profile id has already existed in the small profile image path.Bootless
so is this legal according to facebook TOS?Misrepresent
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?Liber
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.Liber
I just tried your script. It doesn't work the empty matches is always. True.Womack
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.Invidious
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)Werby
Function kept returning file_get_contents(http://graph.facebook.com/cindypizzaplace): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad RequestScornik
Function kept returning file_get_contents(graph.facebook.com/cindypizzaplace): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad RequestRealist
Thanks, updated the answer with new solution. FB now requires access token to get anything from Graph API.Invidious
Where do you use graph api in your code? I dont see any.Zamboanga
I get only 1 to 6 results. No more :(Zonate
N
41

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

Nylanylghau answered 22/5, 2013 at 13:6 Comment(10)
Could you please provide some details?Nylanylghau
@verbumSapienti this answer is totally valid as of June '15Aras
@jirungaray Yes. You should replace "3217701..." from original URL in answer to your page ID which you can find out here: findmyfacebookid.com. Also this feature may be missing on mobile version, so try it from a desktop.Aras
Can we embed that in an iFrame ?Scornik
Did you try? Any issues?Nylanylghau
This doesn't give you all the fans. I think the max is 10K. The reason for that is that your browser cannot handle more than that.Zamboanga
Still works at 2016. Just make sure you are logged in and you are connected to the related FB page (e.g. Admin, Editor, Advertiser)Volkan
@Volkan But it won't give you all the fans.Zamboanga
@Zamboanga yes, it won't. That's too many to give in one list only. Logically, it really has to be chopped.Volkan
The links point to "People who like HITEC", not relevent to the answer anymoreGyniatrics
R
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 :(

Rosenarosenbaum answered 24/1, 2013 at 9:48 Comment(4)
Can we embed that in an iFrame ?Scornik
Max is 10,000 now.Zamboanga
not working anymore? I guess you have to own the pageSpinner
I don't know if there's another way to get your page id, but I found this page for that: findmyfbid.comFatima
D
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.

Dowitcher answered 10/6, 2014 at 11:9 Comment(0)
B
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

Birck answered 17/6, 2015 at 9:21 Comment(0)
U
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

Up answered 27/10, 2011 at 12:31 Comment(2)
Page is not foundCzarevna
@Czarevna 5 years ago it was there. But now Facebook Like Query deprecatedUp
B
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"
Brahms answered 5/12, 2013 at 21:31 Comment(0)
W
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.

Whimper answered 17/2, 2020 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.