Displaying Facebook Fan & Twitter Follower Counts on a Web Page

We have an upcoming project (now launched) where we wanted to show the latest, greatest Facebook fan and Twitter follower counts for our official presences on those services. I put together some really simple JavaScript that does just that and I'm sure others could use it as well. As always the code requires jQuery. You should be able to copy the example code into an empty text file, swap in your the usernames of your official accounts, and go from there. If you have any questions about the code please drop me a line in the comments. By the way, there is no error handling on the JSONP requests simply because I guess jQuery has decided JSONP requests won't generate any.

So check out the code on gist.github. Feel free to fork it, comment on it, modify it, or whatever. You can also see the code in action on the Connect with WVU website.

*Updated October 6, 2010: *Added support to automatically insert commas. The counts now look a lot better.

*Updated November 16, 2010: *A user posted a simple implementation of this concept written in PHP.

Updated December 29, 2010: Fixed a bug in the Facebook fan count because Facebook changed the name of the count element from ‘fan_count' to ‘likes'. Latest, greatest code.

This article was posted