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

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.

Leave a Reply