How to Get Facebook Page Fan Count Using PHP 2019

How to Get Facebook Page Fan Count Using PHP 2019

How to Get Facebook Page Fan Count Using PHP 2019

It’s easy to get facebook page fan count via Facebook Graph API. On the new version of Graph API, there are many changes. We have created a code that can help you to show likes count of their page.

This is code which you can use:

// Facebook //
function getFacebookLike( $fbid, $token ){ 
$json_string = @file_get_contents('https://graph.facebook.com/v5.0/'. esc_attr( $fbid ) .'/?fields=fan_count&access_token='. esc_attr( $token ) );
$json = json_decode($json_string, true); 
$like_count = isset( $json['fan_count'] ) ? $json['fan_count'] : 0;
return $like_count;
}

You can get access_token by following these steps:

1. Go to Facebook Developer Page and create a new app.

How to Get Facebook Page Fan Count Using PHP 2019How to Get Facebook Page Fan Count Using PHP 20192. After finish create app, go to Facebook Developer Tools and generate a access_token for your app.

How to Get Facebook Page Fan Count Using PHP 2019

How to use Above function?

You can use that function by use this code:

echo getFacebookLike( $fbid = 'wpthemego', 'Your Access_token' );

That’s it! Hopefully it is useful for you!

maint

I'm Mai Nguyen - who is working as a digital marketer at WPThemeGo. I love writing the blog and reading books. Really hope that my sharings are useful for you! Follow my blog at Best WordPress Themes

Best selling multi vendor wordpress themes

 Best Selling Multi Vendor MarketPlace WordPress Themes

You might also like

Leave Your Comment

x
Quà Tết Cao Cấp Hộp quà tết Giỏ quà tết Túi quà tết