ASP.Net del.icio.us API integration with C#

I’ve been playing around with getting my blog to automatically post to del.icio.us when a new post is added (just because I can) and it’s actually very easy to talk to the del.icio.us API. To get any communication going, just create a WebRequest, add authentication, and away you go. The bit of code below reads an XML document of all posts into a string:

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(“https://api.del.icio.us/v1/posts/all”);
myReq.Credentials = new NetworkCredential(username,password);//Both as strings
HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
myReq.UserAgent = “K-blog del.icio.us adder”;//Optional
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader (receiveStream, System.Text.Encoding.UTF8);
string deliciousResponse = readStream.ReadToEnd();
readStream.Close();
receiveStream.Close();
response.Close();

And now all my blog posts are linked on del.icio.us. There are a few problems linked with having to use the API sparingly (otherwise they start sending 503 headers back) so you can’t post too much at once, but it works as well as it’s going to.

Advertisements
This entry was posted in Programming. Bookmark the permalink.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s