2

I've got a twitter plugin that prints t.co links. How can I 'un-short' them with jQuery? Is there a library I could use?

I did some searches but I can't find anything. Maybe I'm searching on the wrong thing...

Kees C. Bakker
  • 32,294
  • 27
  • 115
  • 203
  • 1
    Crap.. I marked the wrong question as "duplicate". Sorry. – Anirudh Ramanathan Feb 07 '13 at 20:01
  • 1
    @Plynx Did you really reference a possible duplicate AS a possible duplicate? – Ian Feb 07 '13 at 20:04
  • @Ian it wasn't marked as a duplicate until 9 minutes ago, so no. At the least, we can all consolidate the questions on the one with the most helpful answers. – Plynx Feb 07 '13 at 20:11
  • @Plynx Jeez I'm dumb. I saw the date on the actual question, and didn't bother to look at the hidden comment that showed it. – Ian Feb 07 '13 at 20:15

1 Answers1

5

I made a fiddle here: http://jsfiddle.net/duotrigesimal/XB8Uf/

It makes a request to the api at LongURL (http://longurl.org/api#expand-url) to get the expanded url.

var tests = [
    'http://t.co/NJwI2ugt', 
    'http://www.google.com' //nothing should happen
];

var expander = {
    expand: function (url, callback) {
        $.ajax({
            dataType: 'jsonp',
            url: 'http://api.longurl.org/v2/expand',
            data: {
                url: url,
                format: 'json'
            },
            success: function(response) {
                callback(response);
            }
        });
    }
};

for(i in tests) {

    expander.expand( tests[i], function(response) {
        $('#output').append(response['long-url']+'<br>');
        console.dir(response);
    });

}
Jonathan Wren
  • 3,662
  • 23
  • 29