Get Facebook “Like” count for every page on my domain

谁说胖子不能爱 提交于 2019-11-28 03:19:50
John Macon

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.

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:

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.

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;

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

Maybe you can just query the number of likes for each page each time the page is viewed. This won't be precise, but keeping in mind that the most popular pages will be viewed more often it might be good enough.

Additionally, you can use a batch process to query the number of likes of all the page or at least the top N last created ones every couple of hours. Most of the time you won't get the correct result, but in most cases your users don't need the correct result but a good enough approximation.

If you just need the count from every page, Super Social Media Tracker could provide that.

http://apps.microsoft.com/windows/en-US/app/super-social-media-tracker/a56c8971-42e2-4eb4-9b05-7e52233b4e1e

But it's slow for massive pages.

After some looking around, we may be better off using FQL with graph API:

http://graph.facebook.com/fql?q=select%20comment_count%2C%20share_count%2C%20like_count%20from%20link_stat%20where%20url%20%3D%20%22http%3A%2F%2Fmashable.com%2F2013%2F01%2F30%2Ffacebook-twitter-blackberry-10%2F%22

Results are

{
   "data": [
      {
         "comment_count": 3,
         "share_count": 91,
         "like_count": 5
      }
   ]
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!