Get Facebook Like, Share And Comment Count Using PHP
Last Updated : Jul 1, 2023
In this tutorial we will show you how to get facebook likes, shares and comment count using php, now getting Facebook data like facebook likes, facebook share, facebook comment count is easy just because of facebook new api you only need to pass webpage URL and in return you will get URL likes, shares, and comment counts.
You may also like Extract URL Data Like Facebook Using PHP.
To Get Facebook Like, Share And Comment Counts It Takes Only Two Steps:-
- Make a HTML file and define markup
- Make a PHP file to get facebook data
Step 1. Make a HTML file and define markup
We make a HTML file and save it with a name facebook_data.html
<html> <body> <div id="wrapper"> <form method="post" action="get_data.php"> <p>Enter URL</p> <input type="text" name="url"> <input type="submit" name="submit"> </form> </div> </body> </html>
In this step we create a form to enter URL and submit it to get facebook data from get_data.php file which we were going to create in next step.
You may also like Auto Post On Facebook Using PHP.
Step 2. Make a PHP file to get facebook data
We make a PHP file and save it with a name get_data.php
<?php if(isset($_POST['submit'])) { $url=$_POST['url']; $rest_url = "http://api.facebook.com/restserver.php?format=json&method=links.getStats&urls=".urlencode($url); $json = json_decode(file_get_contents($rest_url),true); echo "Facebook Shares = ".$json[0][share_count]; echo "Facebook Likes = ".$json[0][like_count]; echo "Facebook Comments = ".$json[0][comment_count]; } ?>
In this step we get the url and then we use facebook api url and insert our url in facebook api link to get all the Facebook details of that link like URL likes, shares and comment count.
You may also like Login With Facebook Using PHP.
Thats all, this is how to get facebook like, share and comment counts using PHP. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
I hope this tutorial on get facebook like, share and comment counts using PHP helps you and the steps and method mentioned above are easy to follow and implement.