Check out my latest project: Full Frontal JavaScript Conference

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

Here's the source code for your own hosting: http://remysharp.com/downloads/tinyurlapi.php

There are full instructions and examples on the page along with a demonstration.

Note that since creating the script, TinyURL have changed their page so we can't create tinyurls on the fly (though we can still look up), so I've plugged in is.gk instead for creation.

27 Responses to “TinyURL JavaScript API”

  1. 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.

  2. Hay Remy, nice job, thanks for this. You mentioned that we could get the code to host on our own site - is that possible? If so, could you please tell me where I can download it? Great stuff though, very useful - thanks ;)
    btw I am not the same Jamie as above! Just noticed that - hi Jamie ;)
    Jamie

  3. @Jamie + Jamie - yep - I've added a link to the source code in the original post above. Cheers.

  4. Thanks and good job!

    I writed about your api in my blog and I'm using it on feedky.com

  5. @Remy @jimbo

    Hi!

    As an ISP in Spain has blocked TinyURL (it seems that ISP has added them to their own 'axis of evil'), I edited the script for modify not only the title, but also the href, the link itself.

    I haved posted the script here:
    http://userscripts.org/scripts/show/35928

    Thanks for your job!

  6. This is amazing. Ingenious to parse the DOM of the preview page.

    I've incorporated your code into my site, which fetches and displays my Twitter tweets... now that I can do the reverse tinyurl lookup, I can parse youtube links that I've posted and embed them in the page.

    Thank you!

  7. I ran a quick test and it seems that Arun's method above of using an fsock & reading the header is about 3x faster than parsing the DOM... also seems less prone to getting broken by cosmetic changes at tinyurl. His code needs a bit of restructuring to be error safe, but I would consider incorporating his method into your code.

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight