How to un-shorten t.co links with jQuery? [duplicate]

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

Answers:

Answer

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);
    });

}

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.