Get Facebook Total Comments, Total Likes, Total Shares Of A Given URL
Posted by in Facebook Graph API February 20, 2012 4 Comments

This is a method uses to get Facebook information such as total comments, comment count, total likes, like count, total shares, share count, total count, click count, comment box count of one or more links (URLs) that are shared on Facebook or integrated with Facebook.

It’s useful when you want to store those information into database in order for users be able to sort or filter your entries by most Facebook comments, shares, likes, clicks, etc.

Get Facebook Total Comments, Total Likes, Total Shares

Simple run this URL on your browser, no permission required.

http://api.facebook.com/restserver.php?method=links.getStats&urls=_url_

Let’s replace _url_ with your URL. For example, if you want to get share statistic of this url: http://4rapiddev.com/facebook-graph-api/get-or-find-facebook-profile-id-number/, you will need to run this:

http://api.facebook.com/restserver.php?method=links.getStats&urls=http%3A%2F%2F4rapiddev.com%2Ffacebook-graph-api%2Fget-or-find-facebook-profile-id-number%2F

Or click here to view the result.

Note: you will need to Encode the URL to ensure it works properly. Run the Online URL Encode Tool to encode your URL before trying.

Example of the result:

<links_getStats_response xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
<link_stat>
	<url>http://4rapiddev.com/facebook-graph-api/get-or-find-facebook-profile-id-number/</url>
	<normalized_url>http://www.4rapiddev.com/facebook-graph-api/get-or-find-facebook-profile-id-number/</normalized_url>
	<share_count>28</share_count>
	<like_count>14</like_count>
	<comment_count>1</comment_count>
	<total_count>43</total_count>
	<click_count>0</click_count>
	<comments_fbid>10150600093930621</comments_fbid>
	<commentsbox_count>0</commentsbox_count>
</link_stat>
</links_getStats_response>

Note: you can also get total comments, comment count, total likes, like count, total shares, share count, total count, click count, comment box count of the list of URL separated by comma (,).

For example:

http://api.facebook.com/restserver.php?method=links.getStats&urls=http%3A%2F%2F4rapiddev.com%2Ffacebook-graph-api%2Fget-or-find-facebook-profile-id-number%2F,http%3A%2F%2F4rapiddev.com%2Fsql-server%2Fdelete-shrink-eliminate-transaction-log-ldf-file%2F

Click here to get the result.

Example of the output:

<?xml version="1.0" encoding="UTF-8"?>
<links_getStats_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
  <link_stat>
    <url>http://4rapiddev.com/facebook-graph-api/get-or-find-facebook-profile-id-number/</url>
    <normalized_url>http://www.4rapiddev.com/facebook-graph-api/get-or-find-facebook-profile-id-number/</normalized_url>
    <share_count>28</share_count>
    <like_count>14</like_count>
    <comment_count>1</comment_count>
    <total_count>43</total_count>
    <click_count>0</click_count>
    <comments_fbid>10150600093930621</comments_fbid>
    <commentsbox_count>0</commentsbox_count>
  </link_stat>
  <link_stat>
    <url>http://4rapiddev.com/sql-server/delete-shrink-eliminate-transaction-log-ldf-file/</url>
    <normalized_url>http://www.4rapiddev.com/sql-server/delete-shrink-eliminate-transaction-log-ldf-file/</normalized_url>
    <share_count>2</share_count>
    <like_count>2</like_count>
    <comment_count>0</comment_count>
    <total_count>4</total_count>
    <click_count>0</click_count>
    <comments_fbid>10150211909918385</comments_fbid>
    <commentsbox_count>0</commentsbox_count>
  </link_stat>
</links_getStats_response>

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at hoan@4rapiddev.com
  • perusi

    Listen to this problem. Let’s say you share on your wall the link of a picture from a website. Let’s say the picture’s address is: http://myaddress.com/mypicture.jpg?468 (the 468 it’s an id)  – now you share  this url on your fb wall. Share, comment and like that address… try the FB restserver API …and… surprise you`ll only see the SHARE counts, not the comment or like counts :( … do you have any idea why?  It’s because of the id from the tail?