So FQL depreciated after August 7,2016. What are you going to do if you have used FQL to get facebook like / share count in your webpage. Facebook wants us to use either SDK or API, But using sdk or api requires separate app for each domain which is not possible if you have service like, where user enters page url to check the like / share count. 

How do you get it?
The trick mentioned in this article is the best alternative to get facebook like / share count after fql depreciation. Using api or anyother methods not the right way, Then how do we going to get the count? After looking at facebook plugins i just found a simple trick to get the facebook like / share count directly.

Facebook javascript SDK
If you would have integrated javascript sdk to show "fb like" button in any of your website and you looked at where the iframe page gets the "html" to display the "like" button then you would got this idea. Yes, the solution is just to make a curl request similar to the one which iframe generates and parse the response to get the count. Look at the code below.
function get_fblikes($url,$type='like'){



	$ch= curl_init();
		CURLOPT_URL => $fb_url.http_build_query($param),
		CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 5.01;Windows NT 5.0)",

	if(curl_errno($ch)>0){ #checks any curl error
		#$fb_html=preg_replace('/s+/', '',$fb_html);

	return $fbc;
FB like count:
Copy above code and simply call "get_fblikes" function with the url you want to see the like count, you're done. 
echo get_fblikes('');
FB share count:
To get facebook share count simply pass the second parameter as 'share',
echo get_fblikes('','share');
If you like to optimize this code further, just set a cookie to avoid the requests sent to facebook on each page load.

	echo $fbc;
}else{ $fbc=$_COOKIE['fbcount']; }

We have used cookies to avoid mass requests to facebook and i think this is the best way to get the facebook like / share count after fql depreciation. Drawback of using this method is, when facebook alters the html in which page like count set, this script will return empty response. But its out of our control, Periodic check and small adjustments to this script means we are on track again, Gud luck.


Comments (6)
  1. Image
    Arthur - Reply

    December 09, 2016

    Does not work: preg_match(): Unknown modifier p

    • Image
      WDS - Reply

      December 09, 2016

      Forgot to escape the backslash in the closing span tag... So we have to escape the slash in the closing span tag by adding backslash I have updated the code to reflect this, it will work now...

    • Image
      WDS - Reply

      December 09, 2016

      Also commented out replace spaces which cause another issue, So updated code in the example will work smoothly... Thanks for your notice about the issue.

Leave a Comment

loader Posting your comment...