views:

127

answers:

3

Hi There,

I have a website where everytime one of our customers reviews a new product it gets tweeted onto the company twitter account automatically.

for the actual tweeting, i am using the twitter api's directly, without any wrapper classes and libraries. its all working fine, except, when the post gets too lengthy, it doesnt get tweeted because twitter has just 140 character limit (my baby nephew can handle more characters than that!)

So what is the best way to shorten the url like bit.ly or tinyurl? do they provide some api's .net users? or does twitter has some url shortening service?

I could have just done something about it, but what I really want is an expert opinion, what is the best thing to do in a case like this.

ps: there are several closely related questions in here, but nothing was close enough for my situation.

+2  A: 

The best thing to do in most cases is use the tool that someone else has already developed and established. So, I'd go with using a service like bit.ly or tinyurl, as you suggested. They're provided for exactly that purpose, and they have APIs (bit.ly at least has a REST API that you could call from your website).

Dan Puzey
Hi, thanks for the answer, I was going to use the api from bit ly and mark your answer, but not a moment sooner i had this answer from Noldorin, the simplest yet! but thanks for answering you did convince me to use an external api.
iamserious
+1  A: 

These services have an API, indeed, that you must attack with the HTTP resources of your language (ie. the APIs are programming language independent). I am pretty sure that if you explore the service's site, you will find a link to their API.

Alternatively, you can host a private URL shortener service on the Web server of your company. It is quite trivial to code...

PhiLho
oh! thanks! then I will have to find the best / easiest way to shorten my urls.. thanks a lot!
iamserious
+8  A: 

The TinyURL service has an incredibly simple API for generating short links.

Just make an HTTP request putting the given website in the query strnig as such:

http://tinyurl.com/api-create.php?url=http://stackoverflow.com/

and the output is your shortened URL! The HTTP response is simply a text/plain document containing the strnig. In this case, http://tinyurl.com/5cttyz.

Example

Noldorin
wow, this is awesome, I can just make a screenscrape and read the string out, that would be easy, but is it the best way to do it? will it have any effect on performance?
iamserious
okay I actually viewed the source of the shortened url, there is no html tags at all, all that contains is shortened url. thats awesome! thanks a lot!
iamserious
Yep, just plain text returned. A simple HTTP GET request in effect. Glad it helps...
Noldorin