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.
2. After finish create app, go to Facebook Developer Tools and generate a access_token for your app.
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!
Leave Your Comment