Implement short urls (tinyurls) for twitter in c#?

1.4k views Asked by At

how do you convert full(long) urls into short urls(like tinyurls) in C# for twitter? I imagine this is probably very simple with the right api. Does anyone know of a good api for doing this?

3

There are 3 answers

0
Jonathan Wood On BEST ANSWER

I just published an article about doing this from bit.ly in a C# application.

Note that bit.ly requires a free login key that you will need in order for the code to work.

1
Enrico On
1
Tiago Ribeiro On

You just need to make a request to http://tinyurl.com/api-create.php?url={url} substituting the {url} with the url you want and read the content of the page.

Here's an example:

public string ShortUrl(string url)
    {
        WebRequest request = WebRequest.Create(string.Format("http://tinyurl.com/api-create.php?url={0}", url));
        Stream stream = request.GetResponse().GetResponseStream();
        StreamReader reader = new StreamReader(stream);
        return reader.ReadLine();
    }