Delicious

From Processing

Jump to: navigation, search
Versions: 1.0+
Contributors: watz
Started: 2006-02-19


del.icio.us is one of the most popular social bookmarking sites out there, and is of interest to information visualizers because of its rich data volume and well-implemented tagging system. External developers can access del.icio.us through the del.icio.us API to read, edit or add posts.

Delicious-java is a Java implementation of the del.icio.us API by David Czarnecki (creator of blojsom). It can be easily be used to access del.icio.us from inside Processing, despite not being written to be a Processing library. In this hack we will look at how it's done.

Contents

Download and install delicious-java

Download the most recent delicious-java distribution from sourceforge.net/projects/delicious-java/. Make sure to download the ZIP file with dependencies, since delicious-java uses several external libraries. The file name should be something like "delicious-1.9-with-dependencies.zip".

When you unzip the downloaded archive you will be presented with a number of JAR files. Some of these are utility libraries used by delicious-java, and one contains delicious-java itself. We will use these as drop-in code for our Processing sketch.

Create a new sketch and use "Show Sketch Folder" to access the folder structure. Create a "code" subfolder inside the sketch folder, and copy the JAR files into it. We should now be ready to play.

A warning about etiquette

Please abide by the rules set out by the del.icio.us API page, the most important one being this:

Please wait AT LEAST ONE SECOND between queries, or you are likely to get automatically throttled. If you are releasing a library to access the API, you MUST do this.

Source Code

Any del.icio.us action is possible using delicious-java, including retrieving, editing, adding or deleting posts. For any serious use of the library, you will need to look at the full Javadoc documentation: http://delicious-java.sourceforge.net/

This simple code shows how to instantiate the Delicious object and retrieve the recent posts from del.icio.us using a username and password. To retrieve all posts, simply use getAllPosts() instead of getRecentPosts(””).

For obvious security reasons, this will not work from an applet.

/**
delicious taken from http://processinghacks.com/hacks:delicious
@author Marius Watz
*/
 
Delicious delicious;
 
void setup() {
 
   // Initiate Delicious object. Replace username and password with your own info.
   delicious=new Delicious("username","password");
 
   // Retrieve recent posts. The result is a List object containing the 
   // Posts as del.icio.us.beans.Post objects. We'll use List.toArray() to
   // give us an array of the Objects in the List.
   Object [] o=delicious.getRecentPosts("").toArray();
 
   // Uncomment the following line to get all posts.
   // Object [] o=delicious.getAllPosts().toArray();
 
   // Convert the Objects to Posts
   Post [] posts=new Post[o.length];
   for(int i=0; i<posts.length; i++) posts[i]=(Post)o[i];
 
   // Print the posts
   println("Del.icio.us posts retrieved: "+posts.length);
   for(int i=0; i<posts.length; i++) println(i+": "+posts[i]);
}

Downloads

You can download the most recent delicious-java distribution from http://sourceforge.net/projects/delicious-java/. Make sure to download the ZIP file with dependencies, since delicious-java uses external libraries.

Related Links

Personal tools