cblemuel
cblemuel

Reputation: 43

Facebook page like counts

how to put this into a <script> or javascript setup

https://api.facebook.com/method/fql.query?format=json&query=select+fan_count+from+page+where+page_id%3D80177638103

that will return the fan_count nos. to a page.

<p> fan_count </p>

Upvotes: 1

Views: 1205

Answers (2)

The Alpha
The Alpha

Reputation: 146191

If you you just want to use plain javascript then you can use

<script>
    function showCount(count){
        if(count)
            document.getElementById('fb_fan_count').innerHTML = 'Total fans : ' + count[0].fan_count;
    }
</script>
<p id="fb_fan_count"></p>
<script type="text/javascript" src="https://api.facebook.com/method/fql.query?format=json&callback=showCount&query=select+fan_count+from+page+where+page_id%3D80177638103"></script>

DEMO.

Upvotes: 1

Jonny Sooter
Jonny Sooter

Reputation: 2417

Haven't tested this but something like this should do the trick. You might just have to replace the results.fan_count with the correct object name that Facebook outputs.

$.getJSON('https://api.facebook.com/method/fql.query?format=json&query=select+fan_count+from+page+where+page_id%3D80177638103', function( results ) {
    $('body').html(
        $.map( results.fan_count, function( obj, index ) {
            return '<p>' + obj.text + '</p>'
        }).join('')
    );
});

Upvotes: 0

Related Questions