Question

I use the TinyURL API in one of my web applications. Until now, it worked fine but, today, an error occurs and I don't know why: I didn't modify my script since September!

Below is the code I use:

function getTinyURL(longURL, success)
{
    var API = 'http://json-tinyurl.appspot.com/?url=',
        URL = API + encodeURIComponent(longURL) + '&callback=?';
    $.getJSON(URL, function(data){
        success && success(data);
    });                  
}

var url='http://[...]'; //A very long URL            
getTinyURL(url, function(data)
{
    if(data.tinyurl)
    {
        $('#link').text(data.tinyurl);
        $('#link').attr('href',encodeURI(data.tinyurl));
    }
    else
    {
        $('#link').text('An error occurs...');
        console.log('ERROR: '+data.error);
        $('#link').attr('href','#');
    }
});

As I already said, even if this code worked well before, today an error occurs. In the console log, this message is displayed: The API call urlfetch.Fetch() required more quota than is available.

I don't understand this message: does it mean that the error comes from TinyURL? Should I change my code or should I wait for TinyURL does something against this error?

Thanks in advance!

Was it helpful?

Solution

The magic behind the json-appspot service is not particularly sophisticated.

If you have ability to add logic to the server side, you can make and run something similar for yourself. You'd need to install a "shim" or gateway script that connects to tinyurl.com, and returns a formatted JSON string.

Some examples:

They do the same thing. With either one you could just drop it on your server, then invoke it from within your pages like this, in jQuery:

var stub = "http://myserver.example.com/api/tinyurlshim.asp?url=",
    urlToEncode = "http://example.com/very/long/url/to/encode?with=query&params=too",
    url = stub + encodeURIComponent(urlToEncode);

$.getJSON(url, function(data) { alert('response: ' + data.tiny);} );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top