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?
Implement short urls (tinyurls) for twitter in c#?
1.4k views Asked by Edward At
3
There are 3 answers
1
On
you can find a nice example on http://psc.fyi
You can find an explanation on http://puresourcecode.com/dotnet/post/Creating-a-URL-shortener-using-ASPNET-WepAPI-and-MVC
1
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();
}
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.