How to count Facebook Likes/Shares/Comments with PHP

steitieh

Well-known member
Joined
Apr 23, 2014
Messages
113
Points
18
If you want to count number of likes, shares or comments on Facebook fan page, I would share these simple codes which created by PHP to get the information

The codes below will get total of comments, likes and shares from whatever Faccebook fan page with JSON.

Code:
function facebook_shares($url){
 
    $fql  = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
    $fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
    $fql .= "link_stat WHERE url = '".$url."'";
 
    $apifql="https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
    $fb_json=file_get_contents($apifql);
    return json_decode($fb_json);
 
}

How to use

For example:

Code:
$fb = facebook_shares('https://www.facebook.com/forumweb.hosting');
 
// facebook share count
echo $fb[0]->share_count;
 
// facebook like count
echo $fb[0]->like_count;
 
// facebook comment count
echo $fb[0]->comment_count;
I hope this code is useful to you and you can use it to count likes, shares, comment from your FB fan page.
 
Older Threads
Replies
5
Views
4,300
Replies
52
Views
46,505
Replies
4
Views
4,016
Replies
5
Views
9,318
Newer Threads
Replies
6
Views
5,570
Replies
5
Views
7,761
Replies
3
Views
2,475
Latest Threads
Replies
1
Views
24
Replies
0
Views
179
Replies
1
Views
39
Replies
2
Views
81
Recommended Threads
Replies
9
Views
2,671
Replies
13
Views
17,625
Replies
14
Views
3,657
Similar Threads
Replies
12
Views
3,911
Replies
1
Views
2,401
jms
Replies
12
Views
5,449

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top