Share

From this page you can share Digg Changes and API Tutorial to a social bookmarking site or email a link to the page.
Social WebE-mail
Enter multiple addresses on separate lines or separate them with commas.
Digg Changes and API Tutorial
(Your Name) has forwarded a page to you from Ajaxonomy
(Your Name) thought you would like to see this page from the Ajaxonomy web site.

Digg Changes and API Tutorial

If you have been using the social network Digg, you have noticed that there are a number of changes. A large portion of the changes involve images and they are working with Photobucket to make may of these changes.

The big changes are described by Kevin Rose on the Digg blog.

* New Universal Taxonomy
Now you can submit news, images, or videos to any category on Digg! Categories will be consistent across the board, which means you can view all media types in a given topic, or view one media type at a time (e.g., only images under the “sports” category). We’re also excited to support the launch with new categories. “Offbeat” will be its own category, with new topics, and we’re adding a whole new “Lifestyle” category with topics like Autos, Food & Drink, and Travel. As always, if you don’t want to see a particular topic or media type on Digg, you can click the customize button in the navigation to filter your view.
* New Images Crawler
Submitting images to Digg is basically the same as submitting news and videos, with a few notable differences. When you submit a link to a web page containing multiple images, Digg will crawl the page and present up to ten image thumbnails from that page for you to choose the one you want. We’ve also added this technology to news submissions.
* Sorting and Duplicate Image Detection
We’ve added a new sort to the images section called “mosaic” view – it’s great for browsing image thumbnails. To help prevent people from submitting duplicate images, we’ve added image recognition technology from Idée Inc.

Also, on the post is that Photobucket used the Digg API to build a Digg channel. After hearing this it got me looking for a good tutorial for using the Digg API. I found a great article on using the Digg API with Ruby on Rails. Of course Rails is a great framework used by many Web 2.0 companies so this may be a useful tutorial.

Below is an excerpt from the post (click here to read the full post).

This tutorial will cover grabbing your most recent submitted articles and displaying the title and number of diggs in a list. With this code you can easily expand to grab any data you wish using the Digg API.

In your template you will need to make the following includes:

<%
require 'open-uri'
require 'rexml/document'
%>

open-uri will be used to grab the data from Digg and rexml will be used to parse the obtained xml data.

The next issue is to grab the data you need. In this case, I will grab the last 20 articles I have submitted ( a complete list of data to be grabbed is here.):

<%
response = open("http://services.digg.com/user/[username]/submissions?appkey=http%3A%2F%2Fthembid.com&type=xml&count=20","User-Agent" => "Demo/0.1").read 
%>

I split the above to three lines, because of the formatting, it should be one line. At the end of this post is a link to a text file with the proper formatting.

username

is your digg username.

appkey

is described here.

type

can be XML, JSON, javascript or PHP. Details are here.

count

determines how many data entries are retrieved. You can read more about arguments (like count) here.

Now that you have the XML stored in the response variable it’s time to use Ruby’s built in XML parser to grab the data you need.

Note that you can put the URI in the open function in your browser to see the full schema of the returned XML and make sure the data you want is retrieved.

The following code creates a new REXML object:

doc = REXML::Document.new(response)

Now lets grab the title (this is an example of retrieving a tag value):

titles = []
doc.elements.each("stories/story/title") { |element|
  titles << element.text
}

Now lets grab the number of diggs (this is an example of retrieving an attribute):

diggs = []
doc.elements.each("stories/story") { |element|
  diggs << element.attributes["diggs"]
}

Let’s now print out our title and number of diggs in a list:

<% count = 0
      while count < 20 
 %>
      <%= titles[count] %> (Diggs: <%= diggs[count] %>)
      <% 
      count += 1
      end 
      %>

That’s it! With these simple instructions you can get, store and display all the data you need to create your next killer Digg API application in Ruby on Rails.

To get the tutorial code in a text file go to the original post by clicking here. It is good to see Digg continue to improve the service and soon they should be adding OpenID support (so it should be look Mom no password). Even though Digg sometimes has things not working properly it is good to see a network continue to change and improve.

Please leave your thoughts on the latest changes on Digg or your experience with the tutorial in the comments.