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.
So in this tutorial we will show you how to get facebook likes, shares and comment count using php.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.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery