Created
January 10, 2013 14:52
-
-
Save bsnux/4502604 to your computer and use it in GitHub Desktop.
Get a short URL using Google API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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