blob: 4609c9f2fc53b3048c2b5584c27836f5451f619c [file] [log] [blame]
Joe Gregorio88243be2011-01-11 14:13:06 -05001#!/usr/bin/python2.4
2# -*- coding: utf-8 -*-
3#
4# Copyright 2010 Google Inc. All Rights Reserved.
5
6"""Simple command-line example for Google URL Shortener API.
7
8Command-line application that shortens a URL.
9"""
10
11__author__ = 'jcgregorio@google.com (Joe Gregorio)'
12
13from apiclient.discovery import build
14
15import pprint
16
17# Uncomment the next two lines to get very detailed logging
18#import httplib2
19#httplib2.debuglevel = 4
20
21
22def main():
23
24 # Build the url shortener service
25 service = build("urlshortener", "v1",
26 developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
27 url = service.url()
28
29 # Create a shortened URL by inserting the URL into the url collection.
30 body = {"longUrl": "http://code.google.com/apis/urlshortener/" }
31 resp = url.insert(body=body).execute()
32 pprint.pprint(resp)
33
34 shortUrl = resp['id']
35
36 # Convert the shortened URL back into a long URL
37 resp = url.get(shortUrl=shortUrl).execute()
38 pprint.pprint(resp)
39
40if __name__ == '__main__':
41 main()