The developer simply sends a specially structured request to Digg's server and the server responds with the desired information. This info - usually delivered in XML - can be converted into a useful format.
How the Digg API Works
In technical terms, the Digg API works because the developer's server sends an HTTP Request to Digg's server. Digg's server follows a given protocol and sends an HTTP Response. Your server parses the data from a standard format and then let's you play with it.
In simpler terms, you send your server to visit a special website on Digg's server. An HTTP GET request - the type used by the Digg API - is just like going to a page called "http://www.digg.com/stories?mode=info&time=weekly."
What Goes In the URL?
The API lays out what needs to go in this specially structured URL. The URL starts with "http://services.digg.com/."
From there, you add what's called an "Endpoint." This is just an extra portion of the URL. A common endpoint would be "stories/topic/programming." Add that to the base URL, and you get the beginning of a request for stories in the programming category.
You then add a bunch of parameters to the end, like "?count=5&offset=10." This determines things like how many articles you get. The API lays out specifically what parameters you can and should use for each possible endpoint.
Put it In Action - Get a Random Article
One possible use for this is to get a random article from Digg's database and display it on your site. Sometimes good articles fall through the cracks - and if they aren't dugg a lot in the beginning, they'll quickly disappear.
By fetching random articles from the past couple of weeks, we might be able to find some diamonds in the rough that previously got overlooked. It also adds some content to our site that isn't floating around on everyone else's site that syndicates Digg's RSS feed.
To do this, you send a request like we discussed earlier. You need to find out the total number of articles in your topic, then come up with a random number between zero and that total. Use this as the 'offset' parameter - telling Digg to skip the first 'x' articles before it gives you one. This tutorial provides all the PHP code you need to make this happen.
This is just the tip of the iceberg. Digg has tons of data available through this API - so once you know what you're doing, you've got a goldmine at your fingertips. This is also just one of many things you can use PHP and XML to accomplish.
Go out, be creative, syndicate.
Published by B. Rock
I'm a recent graduate, a newly wed, and a (no longer first year) teacher. I teach HS Social Studies in a New Jersey city. I graduated from the Rutgers Grad School of Ed in May of 2007. In July '07, I... View profile
- Introduction to PHP 5 and SimpleXML
- The Founder and Visionary of Digg.com, Kevin Rose: Internet Wizard or High-Tech Fr...
- How to Digg Without Getting Your Digg Account Banned
- HD-DVD Scandal Could Spell the End of Digg.com
- How to Add "Digg It!" Button to Your WordPress Blog Posts
- Digg.com Scandal Heats Up - No End of Corruption in Sight
- Digg Bans Legitimate URLs and Draws Fire from the Blogosphere
- The Digg API makes tons of content and data available to you and your scripts.
- An HTTP Request is just a specially formatted URL - as documented in the API.
- You can use this to get a random article from Digg's database and create a link to it on your site.




