How to Get Facebook Page Like Count Without Access Token

[notice type=”error”]This code had been deprecated, follow this link for a more updated code.[/notice]

facebook-count-php
Facebook had change their API flow to work with apps. Previous PHP code to acquire your Facebook page like count might not work anymore. The API needed access token or auth configuration of an apps for it to GET the like count of your Facebook page. Here’s a simple PHP snippet for you to get Facebook page like count without access token. Copy or add this to your custom functions.

[php]<?php
function dez_get_the_fb_like( $fb_pagename = ” ) {
$fburl = ‘https://www.facebook.com/’. $fb_pagename;
$params = ‘select like_count from link_stat where url = "’.$fburl.’"’;
$component = urlencode( $params );
$urls = ‘http://graph.facebook.com/fql?q=’.$component;
$string = file_get_contents( $urls );
if( $string ) {
$fbLIkeAndSahre = json_decode( $string );
$getFbStatus = $fbLIkeAndSahre->data[‘0’];
$likecount = $getFbStatus->like_count;
return $likecount;
} else {
return ‘Data did not exist’;
}
}
?>[/php]

and use this any where in your templates or php application.

[php]<?php
echo dez_get_the_fb_like( $fb_pagename = ‘YOUR PAGE NAME NOT ID’ );
?>[/php]

Check this free WordPress plugin that have built-in social counter widgets.

Comments are closed.

Scroll to Top