Wednesday, January 19, 2011

Get Summary From Feedburner Circulation

Get Summary From Feedburner Circulation: "

There you are wondering to have feed reader accumulate in such condition from all time your blog was publish. Feedburner got the aswer with its awarnes API. once before you can get count of you feed reader, you have to register to feedburner. Once you have one of them, you can modify this onto your websites, or blogsite.


Feedburner awarness API is the programmable interface that allow developer to have manipulation of their feed data, according to its documentation. And if we can se we could do something like this by using the API,


GET feedburner.google.com/api/awareness/1.0/GetFeedData?uri=<feeduri>

or with timeline listing


GET feedburner.google.com/api/awareness/1.0/GetFeedData?uri=<feeduri>&dates=2005-05-01,2005-05-03

And in our application side we can works out with curl that carried from curl library. Here are several ways to get  it into our blog like code below,



<?php
$fburl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=tutopod;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $fburl);
$stored = curl_exec($ch);
curl_close($ch);
$grid = new SimpleXMLElement($stored);
$rsscount = $grid->feed->entry['circulation'];
if($rsscount == '') {$rsscount='0';}
echo $rsscount;
?>

With that code, we can get a daily feed summary. But as it name “Daily”, the counter will remain reset each day and never be the same with passed day. This condition were not fit for someone wanted to get the total amount of their feed reader alongside their website is started to popular.


If we wanted to get all time reader we could use the timeline awareness type API by adding date range after uri path. But some people get it hard to do because they will met this condition while they get the xml value data


GET feedburner.google.com/api/awareness/1.0/GetFeedData?uri=<feeduri>&dates=2005-05-01,2005-05-03

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<feed uri="BurningQuestions" >
<entry date="2005-05-01" circulation="2199" hits="39897" />
<entry date="2005-05-02" circulation="2187" hits="40003" />
<entry date="2005-05-03" circulation="2165" hits="38776" />
</feed>
</rsp>

The multiple circulation would be terrible. but we can do the array trick for the entry xml tag label so there were no mistaking to get all time reader for your websites.



<?php
$feed_id = <your feeduri> // like tutopod in this case
$today = date('Y-m-d', strtotime("now"));
$ago = '2010-12-01';
$feed_url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed_id."&dates=".$ago.",".$today;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $feed_url);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry['circulation'];
$nb = 0;
foreach($xml->feed->children() as $circ){
$nb += $circ['circulation'];
}
return $nb;
echo $nb;
?>

"

No comments:

Post a Comment

Comments