Pages

Monday, January 9, 2012

3

URLtinyfy - a JSONP API for tinyurl.com, goo.gl, etc.

Shortened urls, of blog posts for example, maybe useful in some places (like Twitter). I started first making a hack for Blogger which would offer the reader shortened url(s) for the posts. I came across ggl-shortener and json-tinyurl, which could be used to make goo.gl and tinyurl.com short urls in client side (javascript). But these both Google App Engine applications suffer from overrunning quota, especially json-tinyurl, but sometimes also ggl-shortener.

I think they both simply forward every request to the url shortener services, which always results in url fetch call, and url fetches are quite limited per day in Google appengine. My hands were already itching to make a new appengine app and to excercise my new Python skills, and I thought I could do the url shorting a bit cleverer. And at least have (for my url shortener hack) a service that is not yet, hopefully ever, suffering from quota problems.

Presenting urltinyfy

So I created a new appspot app, urltinyfy, which offers more or less the same APIs as ggl-shortener and json-tinyurl, at least should be compatible. As a bonus there is also support for safe.mn, although they have their own jsonp API so it is a bit redundant. I also coded bit.ly support, but because it needs bitly API key, and they have own jsonp API, I left it out from the "production version". Safe.mn and bit.ly was mainly implemented because I wanted to see if and how it could be done.

My application uses memory cache, so if shortened url is already fetched, it is returned from the cache and no url fetch is needed. This should lessen the possibility to run out of free quota (of url fetches).

I have coded this entirely from a scratch, I have not used any code from ggl-shortener or json-tinyurl. I'm not sure if I'm going to publish the source code of this application, we'll see about that. :)

Parameters

url:  the url to shorten (best to be urlencoded). Only mandatory parameter.
callback or jsonp: the callback function, if jsonp is used
unify: if 1, json will include tinyurl and longurl fields for all services (easy to use, independent of the service), and will pass through title and callID parameters, if found

Usage

If you now use ggl-shortener or json-tinyurl, you should be able to switch to my app with minimal changes, by changing the urls in your javascript like this:

change http://ggl-shortener.appspot.com/?url=... to http://urltinyfy.appspot.com/googl?url=...
change http://json-tinyurl.appspot.com/?url=... to http://urltinyfy.appspot.com/tinyurl?url=...

As alternative "syntax", http://urltinyfy.appspot.com/googl?url=... is the same as http://urltinyfy.appspot.com/?service=googl&url=..., and accordingly with other services.

If you want javascript examples how to use this, do google searches for "ggl-shortener" and "json-tinyurl". I might use this in some url shortening hack later on.


Problems? Suggestions? Please leave a comment.
[Hide comments] - [Show comments]
Click on a single comment to hide/show its text

3 comments:

Beben Koben said... [reply]

wow ... this is very interesting
xixixi :)

Matthew Flaschen said... [reply]

I'm the developer of ggl-shortener. Actually, it did use memcached. I say did, because I've disabled it due to the quota issues, and because I didn't think a revenue stream and billing was realistic for the application.

Despite the memcached, I still exceeded the UrlFetch API Calls and bandwidth quotas (the latter of which is unaffected by memcached) nearly every day.

Good luck, but fair warning.

MS-potilas said... [reply]

@Matthew Flaschen
Hi Matthew,

and thank you for your comment. You are right about the urlfetch and bandwidth quotas. I've tried to further compensate those with cache-control, max-age set to 86400 (one day), so if same browser requests the same tiny url, it will get json from browser cache. You might have done the same.

At least for now this app has not run into major quota problems (except for log quota, which was resolved by logging less days). I will definitely not pay for the service, so I'll keep my fingers crossed.

Post a Comment

Related Posts Plugin for WordPress, Blogger...
See the hack
for this dynamic
views icon: