I've figured out how to shorten URLs with the Bitly API (code below). But I don't know how to lengthen them again. The callback in the function below returns an object that has the longurl and the shorturl stored as properties. But I need a function that I can enter a shortURL and retrieve a longURL for my web application. Someone else has asked this on here, but for C, not for JavaScript. LongURL.org has some documentation for how to implement this with their API, but the docs are for PHP and Ruby. Tried to adapt it for JavaScript but got errors.
This seems like something that's probably trivial. Is there a straightforward way to achieve what I want here?
function getShortURL(url, callback)
{
var accessToken = [my access token]
var url = 'https://api-ssl.bitly.com/v3/shorten?access_token=' + accessToken + '&longUrl=' + encodeURIComponent(url);
$.getJSON(
url,
{},
function(response)
{
if(callback)
callback(response.data.url);
console.log(response)
}
);
}
var shortURL;
getShortURL("http://stackoverflow.com/questions/33783996/how-to-make-a-url-shortener-with-the-bitly-api-with-javascrpt-jquery?noredirect=1#comment55334692_33783996", function(url){ shortURL = url; console.log(url) })