Wednesday, 24 April 2013

Display Google Feed Subscriber Count In Text

subscriber feed count in text

However, if you’ve recently migrated your feed from Feedburner to Google Feed, you’ll noticed those codes will no longer work. Here’s the workarounds, for those who wanted to display Google Feed subscriber count in text for better styling.

Previous Code For Feedburner…

This code will only work if you intend to display Feedburner feed count in text, but for those who are already on Google Feed, some changes are required.


  1. //get cool feedburner count  
  2. $whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id";  
  3.   
  4. //Initialize the Curl session  
  5. $ch = curl_init();  
  6.   
  7. //Set curl to return the data instead of printing it to the browser.  
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
  9.   
  10. //Set the URL  
  11. curl_setopt($ch, CURLOPT_URL, $whaturl);  
  12.   
  13. //Execute the fetch  
  14. $data = curl_exec($ch);  
  15.   
  16. //Close the connection  
  17. curl_close($ch);  
  18. $xml = new SimpleXMLElement($data);  
  19. $fb = $xml->feed->entry['circulation'];  
  20. //end get cool feedburner count  

The Solution

Replace line:2 from:
  1. //get cool feedburner count  
  2. $whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id";  
to the following:
  1. //get cool feedburner count  
  2. $whaturl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id";  

The Complete Code

Here’s the complete set of code to display Google Feed subscriber count in text. Remember to replace feedburner-id (line:2) with your real feed ID.
  1. //get cool feedburner count  
  2. $whaturl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id";  
  3.   
  4. //Initialize the Curl session  
  5. $ch = curl_init();  
  6.   
  7. //Set curl to return the data instead of printing it to the browser.  
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
  9.   
  10. //Set the URL  
  11. curl_setopt($ch, CURLOPT_URL, $whaturl);  
  12.   
  13. //Execute the fetch  
  14. $data = curl_exec($ch);  
  15.   
  16. //Close the connection  
  17. curl_close($ch);  
  18. $xml = new SimpleXMLElement($data);  
  19. $fb = $xml->feed->entry['circulation'];  
  20. //end get cool feedburner count  

Troubleshoots

Here are some of the possibilities if the above code don’t work for you:
  • Double check if you’ve correctly replacedhttp://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburner-id withhttps://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id
  • Did you replaced feedburner-id with your actual Feed ID?
  • SimpleXMLElements requires PHP5. If nothing shows up, chances are your web host is still on PHP4. You should contact them about the upgrade.
Spread The Love, Share Our Article

0 comments:

Post a Comment