You can get your Facebook page likes count in JavaScript/JQuery. You will require to pass your Facebook page id or Facebook page name and (App ID|App Secret).
You can get Facebook App ID and Facebook Secret Id from your developers account.
Visit https://developers.facebook.com and select your page in 'My Apps' and now you can get App ID and Secret ID.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
function facebookLikesCount(pageId,access_token)
{
//Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
var url = "https://graph.facebook.com/"+pageId+"?fields=name,fan_count&access_token="+access_token+"";
//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
$.getJSON(url,function(json){
console.log(JSON.stringify(json));
$('#facebookfeed').html("<h2>Facebook Likes: "+json.fan_count+"</h2>");
});
}
//facebookLikesCount('coding4developers','App ID|App Secret');
facebookLikesCount('pageId or page name','App ID|App Secret');
</script>
<div id="facebookfeed">
<h2>Loading...</h2>
</div>
|