3
我怎樣才能爲已經通過使用JavaScript Twitter的API捕獲的Twitter的t.co鏈接的目標URL。使用JavaScript解開t.co鏈接?
我怎樣才能爲已經通過使用JavaScript Twitter的API捕獲的Twitter的t.co鏈接的目標URL。使用JavaScript解開t.co鏈接?
我在這裏做一個小提琴:http://jsfiddle.net/duotrigesimal/XB8Uf/
這使得在LongURL(http://longurl.org/api#expand-url)到API的請求,以獲得展開網址。
我也使用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>');
}
});
}
這樣的鏈接是什麼樣的? – Clive
@ Clive:http://t.co/NJwI2ugt – thejh
http://support.twitter.com/entries/109623 – Camsoft