Skip to content

Instantly share code, notes, and snippets.

@bsnux
Created January 10, 2013 14:52
Show Gist options
  • Save bsnux/4502604 to your computer and use it in GitHub Desktop.
Save bsnux/4502604 to your computer and use it in GitHub Desktop.
Get a short URL using Google API
#!/usr/bin/python
import sys
import requests
import json
headers = {'content-type': 'application/json'}
url = 'https://www.googleapis.com/urlshortener/v1/url'
data = {"longUrl": sys.argv[1]}
response = requests.post(url, data=json.dumps(data), headers=headers)
if response and response.status_code == 200:
print(response.json['id'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment