Created
October 7, 2011 10:19
-
-
Save robbiet480/1269969 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var new_url; | |
var new_json; | |
var data; | |
var chunk; | |
function unshorten(url1) { | |
longurl = http.createClient(80, 'api.longurl.org'); | |
request = longurl.request('GET', "/v2/expand?format=json&url=" +escape(url1), | |
{'host': 'api.longurl.org','User-Agent': 'tweetfixer/1.0'}); | |
request.end(); | |
request.on('response', function (response) { | |
response.setEncoding('utf8'); | |
response.on('data', function (chunk) { | |
new_json = chunk.replace('long-url','longurl'); | |
data = JSON.parse(new_json); | |
new_url = data.longurl; | |
}); | |
}); | |
return data; | |
} | |
console.log(unshorten('http://t.co/evsoxUse', function(url) { console.log(url) } )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment