Created
January 11, 2011 22:08
-
-
Save aezell/775262 to your computer and use it in GitHub Desktop.
Messing around with goo.gl URL shortener API
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 json, urllib2, pprint | |
""" | |
Mess around with goo.gl shortener API | |
""" | |
kind = "SHORTEN" | |
key = "YOUR_KEY" | |
api_url = "https://www.googleapis.com/urlshortener/v1/url?key=%s" % key | |
long_url = "http://www.google.com/" | |
short_url = "http://goo.gl/fbsS" | |
if kind == "SHORTEN": | |
req = urllib2.Request(api_url, json.dumps({"longUrl": long_url}), | |
{'content-type': 'application/json'}) | |
res = json.loads(urllib2.urlopen(req).read()) | |
elif kind == "EXPAND": | |
api_url = api_url + "&shortUrl=%s" % short_url | |
res = json.loads(urllib2.urlopen(api_url).read()) | |
elif kind == "STATS": | |
api_url = api_url + "&shortUrl=%s&projection=FULL" % short_url | |
res = json.loads(urllib2.urlopen(api_url).read()) | |
pprint.pprint(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment