Managing delicious(del.icio.us) bookmarks from BlackBerry Java application

Posted by guptaradhesh on October 14, 2010

Managing delicious(del.icio.us) bookmarks from BlackBerry Java application

With an aim to fetch (manage) the bookmarks in a del.icio.us account to the blackberry device, I searched for java api’s I can get from delicious.

Being able to easily get the java api’s delicious jars (http://sourceforge.net/projects/delicious-java/), i tried using the methods available for managing bookmarks. Got stuck somewhere-

the del.icio.us api’s use java.util.List internally in most of the methods. BlackBerry Api’s doesn’t provide with this java.util.List classes etc. Trying to add java.unit.List jar was a big overhead – moreover the jar I found was of around 20MB+.

As an alternate to it – I tried with using web api’s provided by delicious (http://delicious.com/help/api) . Sending concerned request url would fetch/manage according bookmarks.

Another hitch which I encountered for the same was to send login credentials. I tried sending the request in the form e.g. https://username:password@api.del.icio.us/v1/posts/all – (this url works with firefox but throws error with IE – don’t know way??), but it gives MALFormedUrl Exception.

I found that there is some standard way(not sure whether standard or not) to send login credentials for http-requests. One needs to make Byte64 encoded byte string of “username:password” and attach it as authorization property to the http request.

Being unable to find apache’s commom-codec-3.jar, the Base64 didn’t work. Thankfully, BB Api’s provide with Base64.

The code snippet for fetching most recent bookmarks from a delicious account is as:

String url = "https://api.del.icio.us/v1/posts/recent?";
String loginString = "pensivemode:Aditi01*";
try {
authString = Base64OutputStream.encodeAsString(loginString.getBytes(), 0, loginString.length(), false, false);
catch (IOException e) {
Status.show("problem with base64");
connection = (HttpConnection) Connector.open(url);
connection.setRequestProperty("Authorization", "Basic " + authString);
 InputStream inpStream = connection.openInputStream();

The delicious api returns an XML, which can be parsed using DOM or SAX, as per the data required.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: