Get a URL’s de.licio.us Count Using Javascript

Written by David Walsh on Monday, January 12, 2009


When I put together my new theme, I made it a goal to integrate more of the social bookmarking websites. The benefit to me is that my articles and website will get more attention. The benefit to you is that you can save / bookmark / share my articles easier.

I’ve found the most useful bookmarking site to be de.licio.us. De.licio.us provides a very simple API which allows me access information about who has bookmarked my articles quickly. Here’s how to pull the bookmark count for a specified URL.

The Javascript

<script type="text/javascript">
//the callback -- what do we do with the json response?
function get_delicious_count(info) { 
	//get the number of saves
	var num = info[0].total_posts
	//if none, do nothing
	if(!num) return;
	//if some, I add the number to the end of my link, like at the top of every one of my article posts.
	return $('delic').set({ 
		'text': $('delic').get('text') + ' (' + num + ')',
		'title': num + ' people found this post delicious!'
	});
}
</script>


<script src='http://badges.del.icio.us/feeds/json/url/data?url=http://davidwalsh.name/delicious-url-count-javascript&callback=get_delicious_count'></script>

You need to place your function code before the second javascript tag which goes to de.licio.us to get the statistic information. Note that you need to provide the URL to check and a callback function which will handle the data.

When you receive the data, you can do whatever you want to format it. On this site, I get the count and append it to the “de.licio.us” link at the top of the article. How would you use this data?


Follow via RSS Epic Discussion

Commenter Avatar January 12 / #
Luke says:

I love finding out new things about the numerous API’s bouncing around the social network sites. I actually only became aware that del.icio.us had an API recently, and you’ve pretty much explained the most useful method in full. Thanks mate, good post.

Commenter Avatar January 12 / #
Brenelz says:

Excellent post! Really need this for my blog.

Commenter Avatar January 12 / #
Brenelz says:

BTW, JSON is indeed an easy lightweight way to transfer data.

Commenter Avatar January 12 / #
Binny V A says:

<script src=’http://badges.del.icio.us/feeds/json/url/data?url=http://davidwalsh.name/&callback=get_delicious_count’>

And you can use it on all pages without changing the code.

Commenter Avatar January 12 / #
erent7 says:

That’s really nice. I follow your articles with my patience day and day :=) Thank you

Commenter Avatar March 24 / #
Peter says:

Thank you. I just pooped my pants reading this. Very good!

Be Heard!

I want to hear what you have to say! Share your comments and questions below.

Name*:
Email*:
Website:  


© David Walsh 2007-2010. Contact David Walsh. Powered by the remarkable MooTools javascript framework.