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?
Asked
Active
Viewed 1,477 times
4
-
possible duplicate of [Using tinyurl.com in a .Net application ... possible?](http://stackoverflow.com/questions/366115/using-tinyurl-com-in-a-net-application-possible) – ChrisF Jul 20 '11 at 19:22
-
Possible duplicate of [Using tinyurl.com in a .Net application ... possible?](https://stackoverflow.com/questions/366115/using-tinyurl-com-in-a-net-application-possible) – June7 Mar 21 '18 at 07:39
3 Answers
5
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();
}

Jonathan Wood
- 65,341
- 71
- 269
- 466

Tiago Ribeiro
- 217
- 1
- 3
-
Yeah I tried this, but a proper API is required for my project. This is almost like a work around. I would rather first use, if possible an api built for this, then resort to other methods if necessary. – Edward Mar 04 '11 at 17:14
2
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.

Jonathan Wood
- 65,341
- 71
- 269
- 466
0
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

Enrico
- 3,592
- 6
- 45
- 102