Tweetburner (twurl) - Consuming URL Shortening Services

Posted By:Mohammad ElsheimyPosted Date:February 28, 2011Points:100
Category: ASP.NETURL:http://www.dotnetspark.comArticle of the URL shortening services series. Today, we are going to talk about another hot and easy-to-use service, it's Tweetburner. If you haven't used it before, then it's the time to. We're going to discuss how to use Tweetburner first. After that, we'll inspect its API and learn how to use it in your .NET application.

Overview

Just another article of the URL shortening services series.

Today, we are going to talk about another hot and easy-to-use service, it's Tweetburner. If you haven't used it before, then it's the time to.

We're going to discuss how to use Tweetburner first. After that, we'll inspect its API and learn how to use it in your .NET application.

Introduction

Again, one of the most popular URL shortening services ever.

Today is dedicated forTweetburner(known astwurl,) one of the hot, simple, and easy-to-use shortening services that you can compare tois.gd.

Description

When you visit Tweetburner website (viahttp://tweetburner.comorhttp://twurl.nl,) you can see that it allows users to register to gain more functionalities (specifically, link analytics.) However, at the time of this writing, the account page is disabled for technical issues and nothing interesting would happen if you register there.

One of the hot features of Tweetburner is that it allows you to post your links totwitter(you guessed) andfriendfeedas soon as they're shortened just click 'Share this link' before you leave the page.

Unfortunately, you can't benefit from this sharing feature programmatically, but of course, you can create your own routines.

After shrinking your URL, you get a new short link about 22 characters long (18 in is.gd) prefixed withhttp://twurl.nl.

API

Actually, Tweetburner doesn't help you with anAPI. Instead, it provides you with a simple web page (used for shortening URLs) that you can access it from your code and get your short URLs.

So how you can access this page via your .NET application and fill in its single field? Let's get the idea! If you check theAPI documentation page, you might find that you are required just torequestinformation from that page,postit the required URL via a simple string included in the request body,link[url]={0}(where {0} is the long URL, and just wait for the response that would contain the short URL of course if the function succeed.

Do you find that 'link[url]={0}'strange? Try this with me! Browse to our page,http://tweetburner.com/links, and save it as HTML in your PC (not required, just grab its HTML code.)

Sure we are interested on this magical text box, so scroll down to its definition that looks like this:

<inputid="link_url"name="link[url]"size="30"type="text"/>

Noticethat the text box is given the name 'link[url]', that's why we push 'link[url]={0}' on the request body. Given that hot information, you can push any data to any web form, just get the information required.

Now, let's code! The next function browses to our page,http://tweetburner.com/links, pushes the long URL specified, and gets the short URL back from the server. (Remember to include the namespace System.Net for the code to work properly.)

Noticethat we have specified the POST method because it's required if you are going to change some data in the server. It's worth mentioning too that we have set the content type toapplication/x-www-form-urlencodedbecause it's required if you are going to push data to a web form (it's usually perfect for all web forms except file-uploads.)

In addition, we have included the input required in the request stream.