Situation
I’ve been using a plugin to display the fan count of my facebook-page on my wordpress-blog. A few months ago this plugin (and apparently all similar ones) stopped working. I suppose this happened because facebook changed their api.
Now I’m trying to do this manually.
Display the fan count of my facebook-page, nothing more.
So no like-button next to it, no wrapper around it.
Steps taken
I’ve included the facebook SDK like this:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXXXXXXXX',
xfbml : true,
version : 'v2.4'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
After that I did a quick test, to see if everything works with this:
<div
class="fb-like"
data-share="true"
data-width="450"
data-show-faces="true">
</div>
This works as expected and a basic like-box is displayed.
Problem
Now I’ve been through the docs to figure out how to just display the page-fan-count instead of the like box. Unfortunately this confused me more than it did help.
I understand that I can’t just use something like this:
<div
class="fb-fans"
data-width="450">
</div>
The whole thing seems like such a simple thing to do, but I can’t make sense of it all. Am I aproaching this completely wrong?
Thanks a lot for any kind of help!
Not sure why you can’t use the standard like button, e.g. in box_count mode.
If you specify the URL of your Facebook page as “URL to Like”, then it show you the actual page likes:
Downside is that you can’t really customize it, and that for larger numbers the counts are abbreviated…
It is not THAT simple, unfortunately. There is no plugin for that, so you have to create an App and use the Graph API to get the like count. But you do not need any authorization, you can just use an App Access Token. This would be the API call (use file_get_contents or CURL):
More information: https://developers.facebook.com/docs/graph-api/reference/page#Reading
About Access Tokens in general:
If you don´t want to create an App and deal with the Graph API, you can also just use a platform like SharedCount, they offer a good amount of free calls per day: http://www.sharedcount.com/