Get Facebook "Like" count for every page on my domain

26,058

Solution 1

Actually I would do it this way:

$arrayOfPages = array('url1', 'url2', 'url3');

$listOfPages = implode(',', $arrayOfPages);

SELECT share_count, like_count, comment_count, total_count, url
FROM link_stat
WHERE url IN ($listOfPages)

That would give you all the data with the URL as a unique identifier without having to break Facebook's policy against fake users. You can dynamically create the $arrayOfPages variable from a query on your site's database.

Solution 2

In continuation to Salil's answer, here are the some of the major APIs sharedcount.com are using (full list here: http://sharedcount.com/documentation.php)

You can use sharedcount's API to get a general summary, or write something yourself using the APIs:

Solution 3

It will be difficult to get FB likes for all your pages in one query, but you can get individual share count for every page of your site. Apart from the share count you can also get the breakup of numbers for individual social network for which your site page is shared. Insert you domain name at http://sharedcount.com/?url=http%3A%2F%2Fwww.parasitech.net%2F with appropriate suggestions provided to you. You can get numbers for Facebook, Twitter, Google+, Diggs, Linkedin, Google Buzz, Delicious and StumbleUpon.

Solution 4

Apparently there's no 'LIKE' in FQL. Which was my first suggestion..

Though you can use the "IN" operator, like so:

SELECT share_count, like_count, comment_count, total_count
FROM link_stat
WHERE "http://www.mysite.com/" IN url
ORDER BY like_count
LIMIT 10;

Solution 5

1) create a fake user on fb which will likes only pages from your domain or some other way to save your urls in fb with possibility to get them by FQL later

2) query:

SELECT share_count, like_count, comment_count, total_count
    FROM link_stat WHERE url in (SELECT object_id FROM like WHERE user_id="fake_user_id")

3) don`t forget about decrement on 1 each like count ;), sort and show

Share:
26,058

Related videos on Youtube

KOTJMF
Author by

KOTJMF

Updated on May 12, 2020

Comments

  • KOTJMF
    KOTJMF almost 4 years

    I have integrated the Facebook "Like" button into a lot of pages in my site. I want to display the most "Liked" pages on my site in a list, but I can't figure out how to get that data from Facebook in one request. So far, I have been able to get the "Like" count for individual pages using the following FQL query:

    SELECT share_count, like_count, comment_count, total_count
    FROM link_stat
    WHERE url="http://www.mysite.com/some-page"
    

    However, getting the count for each page on my site one at a time is not really feasible. Aside from having a large number of pages, new pages are being created constantly (new user profiles, new blogs and blog articles, etc), which would make getting complete statistics for my site a complicated process and would involve calling Facebook's API thousands of times.

    Is there a way to get a count of how many times each page on my domain has been "Liked" in one request? Or just the top 10 most "Liked" pages, or something similar?

    • KOTJMF
      KOTJMF about 13 years
      Just an FYI, I have not found a solution to this. I am currently working around it by handling the client events that are fired by Facebook's javascript API to capture the data in my application's database, and querying my local db when I need the most liked pages on my site.
    • XtraBytesLab
      XtraBytesLab almost 11 years
      How, in that case, would you deal with users unliking your pages from outside ( their fb profile itself )?
  • KOTJMF
    KOTJMF about 13 years
    The problem with this is that new pages are constantly being created on the site by the users (new user profiles, new blogs, new blog posts, etc). Having one facebook user who "likes" everything on the site isn't really feasible because there is no way to automatically like everything on my site. I'd have to write a bot to crawl the site and like everything periodically or something. I'm really looking for a way to get the data from one of facevook's APIs without doing a ton of work.
  • KOTJMF
    KOTJMF about 13 years
    This looks really promising but I can't get the query to return more than one result, even though many of the pages on my domain have been "Liked". It only ever seems to return the Like data for the exact URL in the where clause.
  • UIBuilder
    UIBuilder about 13 years
    You can automatically post links (or notes etc) see developers.facebook.com/docs/reference/rest/links.post after that SELECT share_count, like_count, comment_count, total_count FROM link_stat WHERE url in (SELECT url FROM link WHERE owner="fake_user_id")
  • Dave Lugg
    Dave Lugg about 13 years
    May need to look at the FQL syntax then, I've never done it. Perhaps you need to include some kind of wildcard.
  • Mucky Buzzwoo
    Mucky Buzzwoo over 12 years
    There is no Wildcard in Fql :-(
  • Rees
    Rees over 12 years
    has anyone successfully be able to use the above FQL? it does look promising
  • KOTJMF
    KOTJMF about 11 years
    This is a very similar query to the one in the original question, and gets us no closer to the end goal of getting all the "likes" for every page on a site.
  • jave.web
    jave.web almost 10 years
    This requires creating a list of pages first, which you may not have anymore (e.g. deleted pages), is there a way how to get same result without creating the list?