Using Feedburner Awareness API to Get Total Subscribers
Feedburner provides two excellent APIs for its members to manage feeds, get statistics, and other types of data without the need of logging into your feedburner account. Using the Awareness API in particular, you can create a myriad of reports that you use privately or publish on your web site.
In this blog entry, I show you how to use Feedburner's Awareness API in conjunction with ASP to publish the number of subscribers on your web site. I try to make this as easy as possible without making it too technical. The fact that I have done 97% of the code for you makes it easy enough.
I have already given you most of the code below and you simply need to change three lines to fit your own feedburner account and web site. For those of you who do not know what an API is, it stands for Application Programming Interface and is a set of preprogrammed open source code that you can readily use and modify at will to fit the needs of your web site.
This code uses the DOM (Document Object Model) to parse the XML provided to you by Feedburner. Your web server will need to be enabled with ASP. Check with your web hosting company if they provide ASP to you. The DOM is an API itself which allows you to step through lines of HTML or XML. All tags in XML DOM are referred to as nodes. The DOM uses a family scenario to move between nodes (parents, childNodes, and siblings) which you will soon find out.
Ok, enough of the intro. Now, let's get into the main part of this blog entry.
Look at this web address:
http://api.feedburner.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/FEEDBURNERACCOUNT&dates=2005-12-18,2005-12-31
...where FEEDBURNERACCOUNT is your feedburner feed name. You could simply put a link on your web site to this address and everybody who visits your web site can see it. However, the raw XML is not very pretty to your web site visitors and all the days will be broken down. You simply want the total and not the dates broken down and that is what the ASP code will do for you.
If you put this address into your web browser, you will get all of your circulation and hit data for your account from December 18th to December 31, 2005.
The data will show up as raw XML. Now, from this point on, you need to use ASP and the DOM to extract data from that XML. My code below simply goes through every number found between the quotation marks for "circulation" and adds them up. You obviously end up with a total that the ASP will display right on your web site for you.
I am not going to go through every line of the ASP code below, but only the 3 lines which you need to change. Everything else in the code that I have provided for you can simply be copied and pasted verbatim (except for the 3 modifications) right into your text file.
First of all, the line mydoc.load is the line in the ASP that loads an XML file. Simply replace FEEDBURNERACCOUNT with your Feedburner feed name. The ASP will load the XML from your Feedburner feed.
Secondly, replace the date in the date=2005-12-18 part of the mydoc.load line with the first date your feed went live. In this example, I use 2005-12-18 because my feed went live on December 18, 2005. The format must be YYYY-MM-DD. So for example, if your feed started on January 1, 2006, you need to modify this section of the ASP to date=2006-01-01.
The Awareness API's GetFeedData command also requires an end date in the date range, which will always be yesterday's date. In the ASP, I have set up a variable called APIDate which will always calculate the end date dynamically day after day. So, you never need to adjust the ASP to this value. APIDate will automatically handle that for you.
Lastly, you need to change the const StartingNumber=1000 line to whatever starting number you want your subscription to start at. This will add that number to your actual circulation. If you do not wish to increase this number, then set it to 0 (zero).
COPY THE FOLLOWING CODE BETWEEN THE <% and %>
<%
' FEEDBURNER GETFEEDDATA AwAPI
Dim APIDate, rsp, TotalCirculation, feed, entry
APIDate = Year(date) & "-" & Month(date) & "-" & Day(date)-1
Dim mydoc
Set mydoc=Server.CreateObject("MSXML2.DOMDocument.3.0")
mydoc.async=false
mydoc.setProperty "ServerHTTPRequest",true
mydoc.load("http://api.feedburner.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/FEEDBURNERACCOUNT&dates=2005-12-18," & APIDate)
const StartingNumber=1000
Set rsp=mydoc.documentElement
TotalCirculation = 0
For Each feed In rsp.childNodes
If feed.nodeName<>"#comment" Then
For Each entry In feed.childNodes
TotalCirculation = TotalCirculation + entry.attributes.getNamedItem("circulation").text
Next
End if
Next
response.write "" & FormatNumber(TotalCirculation + StartingNumber,0,0,0) & " subscribers!
"
%>
If you are interested in publishing hits as plain text without using the Feedburner Feedcount chicklet, which is a graphic, you can replace the line above entry.attributes.getNamedItem("circulation").text
with entry.attributes.getNamedItem("hits").text.
That is all there is to it. I have provided the most of the ASP code for you and if you have ASP on your web hosting account, then it will work. I am working on a PHP version of this and for those of you who have PHP, I will add this blog entry in the near future.
This Blog is written by Bruce Chambers of Hot Web Ideas, a back end database development firm who has written and marketed proprietary software for online auction web sites, non-commercial blogs, virtual stock exchange web sites, messageboards, web page editors, ecommerce shopping cart systems, online dating web sites and more. Their web site is at http://www.hotwebideas.com and www.WebDesignBilling.com, a web site offering online invoicing and bookkeeping solutions specially for web designers and companies in the web development industry. Hot Web Ideas also writes business plans for web designers and graphic artists to get funding from investors.
In this blog entry, I show you how to use Feedburner's Awareness API in conjunction with ASP to publish the number of subscribers on your web site. I try to make this as easy as possible without making it too technical. The fact that I have done 97% of the code for you makes it easy enough.
I have already given you most of the code below and you simply need to change three lines to fit your own feedburner account and web site. For those of you who do not know what an API is, it stands for Application Programming Interface and is a set of preprogrammed open source code that you can readily use and modify at will to fit the needs of your web site.
This code uses the DOM (Document Object Model) to parse the XML provided to you by Feedburner. Your web server will need to be enabled with ASP. Check with your web hosting company if they provide ASP to you. The DOM is an API itself which allows you to step through lines of HTML or XML. All tags in XML DOM are referred to as nodes. The DOM uses a family scenario to move between nodes (parents, childNodes, and siblings) which you will soon find out.
Ok, enough of the intro. Now, let's get into the main part of this blog entry.
Look at this web address:
http://api.feedburner.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/FEEDBURNERACCOUNT&dates=2005-12-18,2005-12-31
...where FEEDBURNERACCOUNT is your feedburner feed name. You could simply put a link on your web site to this address and everybody who visits your web site can see it. However, the raw XML is not very pretty to your web site visitors and all the days will be broken down. You simply want the total and not the dates broken down and that is what the ASP code will do for you.
If you put this address into your web browser, you will get all of your circulation and hit data for your account from December 18th to December 31, 2005.
The data will show up as raw XML. Now, from this point on, you need to use ASP and the DOM to extract data from that XML. My code below simply goes through every number found between the quotation marks for "circulation" and adds them up. You obviously end up with a total that the ASP will display right on your web site for you.
I am not going to go through every line of the ASP code below, but only the 3 lines which you need to change. Everything else in the code that I have provided for you can simply be copied and pasted verbatim (except for the 3 modifications) right into your text file.
First of all, the line mydoc.load is the line in the ASP that loads an XML file. Simply replace FEEDBURNERACCOUNT with your Feedburner feed name. The ASP will load the XML from your Feedburner feed.
Secondly, replace the date in the date=2005-12-18 part of the mydoc.load line with the first date your feed went live. In this example, I use 2005-12-18 because my feed went live on December 18, 2005. The format must be YYYY-MM-DD. So for example, if your feed started on January 1, 2006, you need to modify this section of the ASP to date=2006-01-01.
The Awareness API's GetFeedData command also requires an end date in the date range, which will always be yesterday's date. In the ASP, I have set up a variable called APIDate which will always calculate the end date dynamically day after day. So, you never need to adjust the ASP to this value. APIDate will automatically handle that for you.
Lastly, you need to change the const StartingNumber=1000 line to whatever starting number you want your subscription to start at. This will add that number to your actual circulation. If you do not wish to increase this number, then set it to 0 (zero).
COPY THE FOLLOWING CODE BETWEEN THE <% and %>
<%
' FEEDBURNER GETFEEDDATA AwAPI
Dim APIDate, rsp, TotalCirculation, feed, entry
APIDate = Year(date) & "-" & Month(date) & "-" & Day(date)-1
Dim mydoc
Set mydoc=Server.CreateObject("MSXML2.DOMDocument.3.0")
mydoc.async=false
mydoc.setProperty "ServerHTTPRequest",true
mydoc.load("http://api.feedburner.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/FEEDBURNERACCOUNT&dates=2005-12-18," & APIDate)
const StartingNumber=1000
Set rsp=mydoc.documentElement
TotalCirculation = 0
For Each feed In rsp.childNodes
If feed.nodeName<>"#comment" Then
For Each entry In feed.childNodes
TotalCirculation = TotalCirculation + entry.attributes.getNamedItem("circulation").text
Next
End if
Next
response.write "" & FormatNumber(TotalCirculation + StartingNumber,0,0,0) & " subscribers!
"
%>
If you are interested in publishing hits as plain text without using the Feedburner Feedcount chicklet, which is a graphic, you can replace the line above entry.attributes.getNamedItem("circulation").text
with entry.attributes.getNamedItem("hits").text.
That is all there is to it. I have provided the most of the ASP code for you and if you have ASP on your web hosting account, then it will work. I am working on a PHP version of this and for those of you who have PHP, I will add this blog entry in the near future.
This Blog is written by Bruce Chambers of Hot Web Ideas, a back end database development firm who has written and marketed proprietary software for online auction web sites, non-commercial blogs, virtual stock exchange web sites, messageboards, web page editors, ecommerce shopping cart systems, online dating web sites and more. Their web site is at http://www.hotwebideas.com and www.WebDesignBilling.com, a web site offering online invoicing and bookkeeping solutions specially for web designers and companies in the web development industry. Hot Web Ideas also writes business plans for web designers and graphic artists to get funding from investors.
