【问题标题】:Unwrap t.co links using JavaScript? [duplicate]使用 JavaScript 解开 t.co 链接? [复制]
【发布时间】:2013-02-08 04:49:17
【问题描述】:

如何获取已使用 JavaScript 通过 Twitter API 捕获的 Twitter t.co 链接的目标 URL。

例如http://t.co/NJwI2ugt

【问题讨论】:

标签: javascript twitter


【解决方案1】:

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

它向 LongURL (http://longurl.org/api#expand-url) 的 api 发出请求以获取扩展的 url。

在这个例子中我也使用了 jQuery,但如果需要,你也可以不使用它。

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

    });

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-04
    • 2011-09-23
    • 1970-01-01
    相关资源
    最近更新 更多