Added Google URL Shortener API sample
diff --git a/samples/api-python-client-doc/main.py b/samples/api-python-client-doc/main.py
index 14f222e..2e9fa8d 100755
--- a/samples/api-python-client-doc/main.py
+++ b/samples/api-python-client-doc/main.py
@@ -74,6 +74,7 @@
<li><a href='/translate/v2'>translate</a>
<li><a href='/prediction/v1.1'>prediction</a>
<li><a href='/shopping/v1'>shopping</a>
+ <li><a href='/urlshortener/v1'>urlshortener</a>
</ul>
""")
diff --git a/samples/buzz/buzz.py b/samples/buzz/buzz.py
index 18bdfb0..72ef991 100644
--- a/samples/buzz/buzz.py
+++ b/samples/buzz/buzz.py
@@ -29,11 +29,13 @@
http = httplib2.Http()
http = credentials.authorize(http)
- p = build("buzz", "v1", http=http, developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
+ p = build("buzz", "v1", http=http,
+ developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
activities = p.activities()
# Retrieve the first two activities
- activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
+ activitylist = activities.list(
+ max_results='2', scope='@self', userId='@me').execute()
print "Retrieved the first two activities"
# Retrieve the next two activities
@@ -44,16 +46,17 @@
# Add a new activity
new_activity_body = {
"data": {
- 'title': 'Testing insert',
- 'object': {
- 'content': u'Just a short note to show that insert is working. ☄',
- 'type': 'note'}
- }
+ 'title': 'Testing insert',
+ 'object': {
+ 'content': u'Just a short note to show that insert is working. ☄',
+ 'type': 'note'}
+ }
}
activity = activities.insert(userId='@me', body=new_activity_body).execute()
print "Added a new activity"
- activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
+ activitylist = activities.list(
+ max_results='2', scope='@self', userId='@me').execute()
# Add a comment to that activity
comment_body = {
diff --git a/samples/urlshortener/main.py b/samples/urlshortener/main.py
new file mode 100644
index 0000000..4609c9f
--- /dev/null
+++ b/samples/urlshortener/main.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python2.4
+# -*- coding: utf-8 -*-
+#
+# Copyright 2010 Google Inc. All Rights Reserved.
+
+"""Simple command-line example for Google URL Shortener API.
+
+Command-line application that shortens a URL.
+"""
+
+__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+
+from apiclient.discovery import build
+
+import pprint
+
+# Uncomment the next two lines to get very detailed logging
+#import httplib2
+#httplib2.debuglevel = 4
+
+
+def main():
+
+ # Build the url shortener service
+ service = build("urlshortener", "v1",
+ developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
+ url = service.url()
+
+ # Create a shortened URL by inserting the URL into the url collection.
+ body = {"longUrl": "http://code.google.com/apis/urlshortener/" }
+ resp = url.insert(body=body).execute()
+ pprint.pprint(resp)
+
+ shortUrl = resp['id']
+
+ # Convert the shortened URL back into a long URL
+ resp = url.get(shortUrl=shortUrl).execute()
+ pprint.pprint(resp)
+
+if __name__ == '__main__':
+ main()