Joe Gregorio | 652898b | 2011-05-02 21:07:43 -0400 | [diff] [blame^] | 1 | # version: v1 |
| 2 | # title: Command-line sample for the Google URL Shortener API. |
| 3 | # scope: https://www.googleapis.com/auth/urlshortener |
| 4 | # description: Simple command-line example for Google URL Shortener API that shortens a URI then expands it. |
| 5 | |
| 6 | url = service.url() |
| 7 | |
| 8 | # Create a shortened URL by inserting the URL into the url collection. |
| 9 | body = {"longUrl": "http://code.google.com/apis/urlshortener/" } |
| 10 | resp = url.insert(body=body).execute() |
| 11 | pprint.pprint(resp) |
| 12 | |
| 13 | short_url = resp['id'] |
| 14 | |
| 15 | # Convert the shortened URL back into a long URL |
| 16 | resp = url.get(shortUrl=short_url).execute() |
| 17 | pprint.pprint(resp) |