27 Mar
TinyURL JavaScript API
I've been writing a bookmarklet for Twitter that will allow you to post URLs to Twitter, that are first compressed using TinyURL.
So I thought I'd share the TinyURL callback API I wrote.
The API allows the dynamic creation of TinyURLs on the fly using JavaScript.
The API url is: http://remysharp.com/tinyurlapi
There are full instructions and examples on the page along with a demonstration.
it works but it has to go through your site rather then test.com, you need to provide the backend php script in order for other sites to really use it.
@Mongoose - sorry, I didn't make that clear. The guts of the API is a little server side script that I'm hosting to create a new tinyurl. I've changed the example script to point to my real domain (rather than test.com).
If you want, I can provide the actual script and you can host it yourself if that's more valuable.
Thanks Remy
This is cool! I really think tinyurl is a great service and twitter is making it even more popular. Such APIs are indeed quite helpful. Using your API is there a way to do a reverse lookup?
Akshay
@Akshay - I've tweaked the TinyURL API to also support reverse lookups. If you enter a tinyurl instead of a normal URL, it will workout where the URL is pointing to.
e.g. http://remysharp.com/tinyurlapi?url=http://tinyurl.com/yrgztp
I've also upgraded the api to handle 'RESTful' type requests, e.g.
http://remysharp.com/tinyurlapi/remysharp.com/2007/03/27/tinyurl-javascript-api/
and visa versa:
http://remysharp.com/tinyurlapi/tinyurl.com/yrgztp
You can use the official API too, for example:
http://tinyurl.com/api-create.php?url=http://www.google.com/
You can send the URL by GET (as the example) or by POST
@pedro - of course - this isn't meant to replace the service, but to allow developers to pull in tinyurls on the fly within JavaScript driven web apps.
really nice api!
with using your api, I write a greasemonkey script for twitter (and any web sites) that shows the original URL in tooltip.
http://userscripts.org/scripts/show/8918
thanks again for your good job!
@Jimbo - thanks for the script - I had spotted it was being used as greasemonkey script from my logs but couldn't find it on the Internet.
I'm going to have a think about upgrading the API to handle multiple URLs to reduce the number of calls. Comma separated URLs and the response can be an array of the resolved URLs in the same order requested.
Do you think your script will benefit from this? I guess the only problem may be if you request one URL it will return as a string - so you'll have to sniff the object type in the callback so the API is backward compatible.
@Remy - I'm ready to change my script, althought it won't be affected by the upgrading. (I don't use the calback function correctly :P)
Remy, It is interesting. How are you doing reverse lookups? Are you sending any HEAD socket queries or fopen+regexp?
Thanks.
@Arun - pretty easy - I use the preview.tinyurl.com path and do a simple bit of DOM querying to find the value of the reverse lookup.
I could have used a HEAD query, but the way I wrote the code, the forward and reverse lookup use the same code.
I wrote a small snippet of PHP today to resolve tinyurl.
http://www.webforth.com/2007/07/resolving-tinyurls-to-the-desination-url
How could I modify the code to remove the bullet point from the beginning of each twitter?
@William - did you mean to post this comment on the TinyURL API post, or did you mean to do it on the Add twitter to your blog post?
Either way, it's best done using CSS:
Hi,
Here's a web service for resolving TinyURLs, based on Dapper:
http://ghill.customer.netspace.net.au/embiggen/
You can use it as a browser button (bookmarklet) or a button your page. It will convert all TinyURLs on the current page into their full version.
-Greg.
[...] (11/14/07): So after looking over a few pages, and the inexplicable problems I had with the JSON api, I’ve updated the script to use the [...]
The TinyURL API cuts off any URL variables I have that begin with "&". For example, in the following URL:
http://www.delawareonline.com/apps/pbcs.dll/article?AID=/20080508/NEWS/80508030&source=twitter
"&source=twitter" gets cut off when I attempt to use the URL with the API. Any suggestions?
Did you ever post the server script? Your javascript sample is no longer functional. It only seems to be returning null.
@Daniel - crap, the Tinyurl monkey has been set loose. I'll round him up and set him back to work in no time.
Hey would it be possible to have this put onto my website?
I run a little game you see and users are cheating by sending out tinyURL links
And the other members are clicking them and coursing chaos.
Thanks, Jamie.