Skip to content

Instantly share code, notes, and snippets.

@bmc
Created April 1, 2011 21:08
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 bmc/898862 to your computer and use it in GitHub Desktop.
Save bmc/898862 to your computer and use it in GitHub Desktop.
Access goo.gl from Python
# Test of Goo.gl Python front-end available at
# http://code.google.com/p/python-googl/source/checkout
#
# Some kind of JSON parser must be installed. 'simplejson' works fine.
#
# See
# http://code.google.com/apis/urlshortener/v1/getting_started.html#shorten
# for Goo.gl API info.
import googl
if __name__ == '__main__':
import sys
# NOTE: Constructor DOES support an API key, which the Google
# documentation (see above) recommends.
g = googl.Googl()
for url in sys.argv[1:]:
# returns a hash
hash = g.shorten(url)
shortened = hash['id']
print('%s -> %s' % (url, shortened))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment