Start Using Delicious and FeedBurner API, Quick and Easy!
Once you start using and manipulating API's, web services and other site's feeds it's hard to stop.
The first API I ever used was flickr. I used it in my 26things project and then I really tested it in manipulating the RSS feed of my Flickr favorites for my Life Feed. Since then everywhere I go on the Internet I'm always looking for that orange feed icon in my URL bar and an 'API doc' link in the footer.
Here's some of my new favorite uses of some popular Internet services.
FeedBurner Subscriber Count
Recently I've added a number associated with the number of subscribers I have on my RSS feeds, FeedBurner has a graphical icon that you can use, but it's not that attractive and I really want to be able to customize it! As it turns out, that subscriber number was a really easy thing to generate using FeedBurner's API.
Steps to Display the number of Subscribers on your FeedBurner feed
- Sign up with FeedBurner and have it handle your feeds. Not sure why you would do that
- Enable the Awareness API for the feed you want to pull the number of subscribers from
- Use this little snippet of code, replacing
FEED-NAME-HEREwith your FeedBurner's feed name. FeedBurner API doc
PHP
<?php
$feed = 'http://api.FeedBurner.com/awareness/1.0/GetFeedData?uri=FEED-NAME-HERE';
$subject = file_get_contents($feed);
$pattern = '/circulation="([0-9]+)"/';
preg_match($pattern, $subject, $matches);
$feed_count = $matches[1];
echo $feed_count . ' subscribers!';
?>
And TADA, now you can textually display the number of subscribers you have from FeedBurner. This is considerably more customizable than their graphical representation.
Note: Do remember that most services have a limit on the number of API pings you can make in any given time frame. Be sure to cache your results to avoid hitting this restriction. This demo did not include caching results, you are on your own for that one!
del.icio.us Bookmarks
Today I spotted a few visitors originating from del.icio.us, so I went and peeked around and saw that a handful of my pages are bookmarked by people. There's no easy way for me to tell which pages are bookmarked but I thought it would be great if I could find a way to use the del.icio.us API to display the number of people who have bookmarked an entry on that entry. If 6 other people have already bookmarked a page I would guess it is more likely that someone else will bookmark the page too, as long as they know everyone else is doing it. Much like Digging. A person is usually more likely do Digg an article if other people are Digging it.
The del.icio.us API leaves something to be desired so I had to do some snooping of my own.
It turns out that when someone bookmark's a page in del.icio.us the MD5() encryption of that URL is the unique ID used to reference that bookmark. And that unique id can be used to grab the RSS feed.
I'm going to use one of my del.icio.us bookmarked entries as an example: Simple Hide and Show with Prototype
- URL: http://blog.ninedays.org/2007/12/18/simple-hide-and-show-with-prototype/
- MD5 of URL: 34fc4467dccd40f69502c0c9faf4fe30 (MD5 generator).
- del.icio.us page: http://del.icio.us/url/34fc4467dccd40f69502c0c9faf4fe30
- del.icio.us Feed: http://feeds.del.icio.us.com/rss/url/34fc4467dccd40f69502c0c9faf4fe30
All I had to do was grab the del.icio.us Feed using MagPie and count the items to find out how many people had bookmarked the defined page.
PHP
<?php
// Path to magpie rss_fetch.inc file
// Get magpie: http://magpierss.sourceforge.net/
require_once('../../includes/libs/magpie/rss_fetch.inc');
/* use the following for wordpress, otherwise replace with your values */
$permalink = get_permalink();
$title = get_the_title();
/* end wordpress ready code */
$delicious_rss = 'http://del.icio.us/rss/url/' . md5($permalink);
$delicious_url = 'http://del.icio.us/url/' . md5($permalink);
$delicious_link = 'http://del.icio.us/post?url='.$permalink.'&title='.trim(urlencode($title)).'';
$del_rss = fetch_rss($delicious_rss);
$del_ct = count($del_rss->items);
if($del_ct == 1){ /* for 1 bookmarker */
echo $del_ct. ' person has <a href="'.$delicious_link.'">bookmarked this page on Del.icio.us</a>! See what <a href="'.$delicious_url.'">they have to say</a>.';
} elseif($del_ct > 1){ /* for many-a-bookmarker */
echo $del_ct. ' people have <a href="'.$delicious_link.'">bookmarked this page on Del.icio.us</a>! See what <a href="'.$delicious_url.'">they have to say</a>.';
} else { /* no one loves this post :( */
echo 'Be the first to <a href="'.$delicious_link.'">bookmark this page on Del.icio.us</a>!';
}
?>
NOTE: MagPie does cache (yay!) but make sure you set it up to do so!
Unfortunately the RSS feed only displays a limited number of bookmarkers (20 if I recall correctly). I'm working on an alternate solution. It will probably involve the del.icio.us API call to https://api.del.icio.us/v1/posts/get. Will update once I get that working!
Popularity: 4% [?]
Previous Articles
Welcome to Ninedays Blog
Glad you decided to stop by. Check out some of my fantastic entries and series and shoot me some comments.
I'll always be bringing you new PHP, MySQL, JavaScript and photography info!
subscribe to the Ninedays Blog feed! * And you mom too.



Recent Comments