Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rickydazla/7b7496ba6ea74fe27e93 to your computer and use it in GitHub Desktop.
Save rickydazla/7b7496ba6ea74fe27e93 to your computer and use it in GitHub Desktop.

Revisions

  1. @dmolsen dmolsen revised this gist Dec 29, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Facebook + Twitter Fan Count
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@

    // grab from facebook
    $.getJSON('https://graph.facebook.com/'+f_page+'?callback=?', function(data) {
    var fb_count = data['fan_count'].toString();
    var fb_count = data['likes'].toString();
    fb_count = add_commas(fb_count);
    $('#fb_count').html(fb_count);
    });
  2. @dmolsen dmolsen revised this gist Oct 7, 2010. 1 changed file with 27 additions and 6 deletions.
    33 changes: 27 additions & 6 deletions Facebook + Twitter Fan Count
    Original file line number Diff line number Diff line change
    @@ -2,20 +2,41 @@
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    var fb_page = "wvumountaineers"; // the page name for your fan page, e.g. the 'wvumountaineers' part of http://facebook.com/wvumountaineers
    var twitter_page = "westvirginiau"; // the account name for your main twitter account
    var f_page = "wvumountaineers"; // the page name for your fan page, e.g. the 'wvumountaineers' part of http://facebook.com/wvumountaineers
    var t_page = "westvirginiau"; // the account name for your main twitter account

    function add_commas(number) {
    if (number.length > 3) {
    var mod = number.length % 3;
    var output = (mod > 0 ? (number.substring(0,mod)) : '');
    for (i=0 ; i < Math.floor(number.length / 3); i++) {
    if ((mod == 0) && (i == 0)) {
    output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
    } else {
    output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
    }
    }
    return (output);
    } else {
    return number;
    }
    }

    // when document is ready load the counts
    $(document).ready(function(){

    // grab from facebook
    $.getJSON('https://graph.facebook.com/'+fb_page+'?callback=?', function(data) {
    $('#fb_count').html(data['fan_count']);
    $.getJSON('https://graph.facebook.com/'+f_page+'?callback=?', function(data) {
    var fb_count = data['fan_count'].toString();
    fb_count = add_commas(fb_count);
    $('#fb_count').html(fb_count);
    });

    // grab from twitter
    $.getJSON('http://api.twitter.com/1/users/show.json?screen_name='+twitter_page+'&callback=?', function(data) {
    $('#twitter_count').html(data['followers_count']);
    $.getJSON('http://api.twitter.com/1/users/show.json?screen_name='+t_page+'&callback=?', function(data) {
    twit_count = data['followers_count'].toString();
    twit_count = add_commas(twit_count);
    $('#twitter_count').html(twit_count);
    });

    });
  3. @dmolsen dmolsen created this gist Sep 27, 2010.
    32 changes: 32 additions & 0 deletions Facebook + Twitter Fan Count
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    var fb_page = "wvumountaineers"; // the page name for your fan page, e.g. the 'wvumountaineers' part of http://facebook.com/wvumountaineers
    var twitter_page = "westvirginiau"; // the account name for your main twitter account

    // when document is ready load the counts
    $(document).ready(function(){

    // grab from facebook
    $.getJSON('https://graph.facebook.com/'+fb_page+'?callback=?', function(data) {
    $('#fb_count').html(data['fan_count']);
    });

    // grab from twitter
    $.getJSON('http://api.twitter.com/1/users/show.json?screen_name='+twitter_page+'&callback=?', function(data) {
    $('#twitter_count').html(data['followers_count']);
    });

    });
    </script>
    </head>
    <body>
    <noscript>The following counts are dynamically populated by JavaScript. You can also directly visit the sources to find the counts at http://facebook.com/[pagename] and http://twitter.com/[accountname]</noscript>

    Facebook fan count: <span id="fb_count"></span><br />
    Twitter follower count: <span id="twitter_count"></span><br />
    <br />
    <em>You could put these spans in nice little badges or something...</em>
    </body>
    </html>