Skip to content Skip to sidebar Skip to footer

Unwrap T.co Links Using Javascript?

How can I get the target URL for a Twitter t.co link that has been captured via the Twitter API using JavaScript. e.g. http://t.co/NJwI2ugt

Solution 1:

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.

I'm also using jQuery in this example, but you can make it work without if needed.

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

for(i in tests) {

    var data = {
        url: tests[i],
        format: 'json'
    };

    $.ajax({
        dataType: 'jsonp',
        url: 'http://api.longurl.org/v2/expand',
        data: data,
        success: function(response) {
            $('#output').append(response['long-url']+'<br>');
        }

    });

}

Post a Comment for "Unwrap T.co Links Using Javascript?"