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

By  on  

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=https://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?

Recent Features

  • By
    CSS Gradients

    With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements.  CSS gradients are another step in that direction.  Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...

  • By
    6 Things You Didn&#8217;t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

Incredible Demos

  • By
    Create a Spinning, Zooming Effect with CSS3

    In case you weren't aware, CSS animations are awesome.  They're smooth, less taxing than JavaScript, and are the future of node animation within browsers.  Dojo's mobile solution, dojox.mobile, uses CSS animations instead of JavaScript to lighten the application's JavaScript footprint.  One of my favorite effects...

  • By
    JavaScript Canvas Image Conversion

    At last week's Mozilla WebDev Offsite, we all spent half of the last day hacking on our future Mozilla Marketplace app. One mobile app that recently got a lot of attention was Instagram, which sold to Facebook for the bat shit crazy price of one...

Discussion

  1. 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.

  2. Excellent post! Really need this for my blog.

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

  4. <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.

  5. erent7

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

  6. Peter

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

  7. @Binny V A: Change the url with : location.href.replace(/\?.*/,'');
    It works for me ;)

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!