Last active
September 29, 2015 04:49
-
-
Save joncasdam/ed430f560b99f2477ce5 to your computer and use it in GitHub Desktop.
This file contains 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
import requests | |
import json | |
api_url = 'https://www.googleapis.com/urlshortener/v1/url' | |
api_key = '' # find here how to get yours https://developers.google.com/url-shortener/v1/getting_started#APIKey | |
url = '{0}?key={1}'.format(api_url, api_key) | |
headers = {'content-type': 'application/json'} | |
params = json.dumps({'longUrl': 'http://www.google.com'}) | |
response = requests.post(url, data=params, headers=headers) | |
if response.ok: | |
print (response.json()['id']) | |
else: | |
print (response.status_code, response.reason) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment