How to find LinkedIn like counts for a website

Zyxware default image1

Most of us have struggled with certain social media buttons to align or fix them in a particular manner. But what if we could get the count figure and display the result in our custom button. Here I wish to share one method to implement this. Let's experiment how to fetch total likes count for a website from LinkedIn.

Pulling likes count of LinkedIn in simple and interesting. The LinkedIn developers have provided one API URL where we could query get our results as response.

https://www.linkedin.com/countserv/count/share

Along with the API URL there is one required parameter 'url' we need to pass our site name and one optional parameter 'type' with tells the format of response we needed (eg: XML or JSON).

Example:https://www.linkedin.com/countserv/count/share?url="http://www.mywebsite.com"&format=json.

Performing this programmatically, please refer the below code:

function linked_count($url) {
   $content = file_get_contents("https://www.linkedin.com/countserv/count/share?url=" . $url . "&format=json");
   $content = json_decode($content);
   $retLinked = $content->{'count'};
   if($retLinked){
          return $retLinked;
   } else {
          return 0;
   }  
}
echo "Linked count: " . linked_count('http://www.mywebsite.com/');

The function linked_count will return the total likes for the site url passed.

Please feel free to get in touch with us, if you face any queries while implementations.