使用 JavaScript 解开 t.co 链接? [英] Unwrap t.co links using JavaScript?
本文介绍了使用 JavaScript 解开 t.co 链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取使用 JavaScript 通过 Twitter API 捕获的 Twitter t.co 链接的目标 URL.
How can I get the target URL for a Twitter t.co link that has been captured via the Twitter API using JavaScript.
推荐答案
我在这里做了一个小提琴:http://jsfiddle.net/duotrigesimal/XB8Uf/
I made a fiddle here: http://jsfiddle.net/duotrigesimal/XB8Uf/
它在 LongURL (http://longurl.org/api#expand-url) 获取扩展后的 url.
It makes a request to the api at LongURL (http://longurl.org/api#expand-url) to get the expanded url.
我也在这个例子中使用了 jQuery,但如果需要,你可以让它工作.
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>');
}
});
}
这篇关于使用 JavaScript 解开 t.co 链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文