Get And Display Your Social Follower Count Using PHP

It is often common for websites to display how many RSS subscribers and followers from various social sites they have. You could say that it’s a way for them to show how popular their site is, and to encourage more visitors to stay. That’s why today, I’d like to feature a tutorial from Alex of DesignWoop on how you can get your social follower count simply by using PHP.

You can take a look at the demo.

This post will only contain the bare essentials of Alex’s tutorial. I’ll provide a link to the complete details at the bottom of this article.

Getting your RSS Feedburner subscriber count – there are a couple of things you first need to do. 1) Be sure that you have your Feedburner Awareness API activated (this will allow you to query the feeds data), and 2) your full RSS URL, which should be parsed in XML format. Once you accomplished these two things you can then proceed to the PHP coding portion as shown below.

/********************************************************************************

 FeedBurner Subscriber Count

********************************************************************************/
/* Send an XML feed of a FeedBurner URL to a PHP variable */

$rss = file_get_contents('http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/designwoop?format=xml');
/* Convert XML feed to an object */

$xml = new SimpleXmlElement($rss);
/* Store the FeedBurner count  */

$rss_count = $xml->feed->entry->attributes()->circulation;

Getting your Facebook Page Like count – this one’s pretty simple. All you have to do is get your Facebook Page’s ID (a 15-digit string) or name (which you may have already provided when you customized your page’s URL). This is used in conduction with the Facebook Graph API, so putting the two together would look something like this: http://graph.facebook.com/[PAGE ID OR NAME]

The PHP code for it would then look like this:

/********************************************************************************
Facebook Like Count
********************************************************************************/
/* Send the FaceBook Graph to a PHP variable */
$facebook = json_decode(file_get_contents('http://graph.facebook.com/158483190866574'), true);
/* Store the  Facebook count  */
$facebook_count = $facebook['likes']; 

Getting your Twitter Follower count – this is pretty much the same as what you do to get your Facebook Page Like count.

To obtain the data from Twitter, use the Twitter API. It will look something like this: https://api.twitter.com/1/users/lookup.json?screen_name=[YOURTWITTERNAME]

The PHP code for this would look something like below:

/********************************************************************************
 Twitter Follower Count
********************************************************************************/
/* Send the Twitter api to a PHP variable */
$twitter = json_decode(file_get_contents('https://api.twitter.com/1/users/lookup.json?screen_name=designwoop'), true);
/* Store the Twitter follower count */
$twiter_count = $twitter[0]['followers_count'];

Once you’ve gathered all of the info, you can then proceed with the HTML portion to show your stats to the user.

Here’s the basic HTML markup:

<div>
 <ul>
 <li><a href="http://feeds.feedburner.com/designwoop"></a></li>
 <li><a href="http://twitter.com/#!/designwoop"></a></li>
 <li><a href="http://www.facebook.com/pages/Designwoop/158483190866574"></a></li>
 </ul>
</div>

Here are the full details on Alex’s complete tutorial. Feel free to show him your appreciation.

Incoming search terms for the article:

Related Posts

Correctly Embed Watermarks In Portrait And Landscape Photos Using Conditional Actions In Photoshop CS6.1

Oregon-Inspired Photoshop Tutorial

Create Google Play’s Tab Navigation Using jQuery And CSS

PS Advanced Compositioning