Skip to content

Instantly share code, notes, and snippets.

@omarish
Created March 24, 2011 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarish/885962 to your computer and use it in GitHub Desktop.
Save omarish/885962 to your computer and use it in GitHub Desktop.
Shorten a URL using goo.gl
#!/usr/bin/python
from urllib2 import urlopen, Request
from urllib import quote
from simplejson import loads
def shorten(url):
u = urlopen(Request('http://goo.gl/api/url', 'url=%s' % quote(url), {'User-Agent':'toolbar'}))
a = loads(u.read())
return a['short_url']
@omarish
Copy link
Author

omarish commented Mar 24, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment