Skip to content

Instantly share code, notes, and snippets.

@sassman
Created April 12, 2013 22:09
Show Gist options
  • Save sassman/5375560 to your computer and use it in GitHub Desktop.
Save sassman/5375560 to your computer and use it in GitHub Desktop.
a small tiny cli wrapper to goole url shortener api
#!/usr/bin/python
import json, sys, urllib2
url = sys.argv[1]
apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
data = {
'longUrl' : url
}
req = urllib2.Request('https://www.googleapis.com/urlshortener/v1/url?key='+apiKey)
req.add_header('Content-Type', 'application/json')
response = json.loads(urllib2.urlopen(req, json.dumps(data)).read())
print response['id']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment