如何缩短与jQuery的t.co链接? [英] How to un-shorten t.co links with jQuery?

查看:132
本文介绍了如何缩短与jQuery的t.co链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以打印 t.co 链接的twitter插件。我怎样才能用jQuery'un-short'他们?有没有我可以使用的图书馆?

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

推荐答案

我在这里做了一个小提琴: http://jsfiddle.net/duotrigesimal/XB8Uf/

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

它使在LongURL上向api发送请求( http://longurl.org/api#expand-url )来获取展开的网址。

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

}

这篇关于如何缩短与jQuery的t.co链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆