Implement short urls (tinyurls) for twitter in c#? [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this q开发者_开发知识库uestionhow 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?
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.
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
精彩评论