Added Google URL Shortener API sample

This commit is contained in:
Joe Gregorio
2011-01-11 14:13:06 -05:00
parent f93b13d30a
commit 88243be815
3 changed files with 53 additions and 8 deletions

View File

@@ -74,6 +74,7 @@ class MainHandler(webapp.RequestHandler):
<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>
""")

View File

@@ -29,11 +29,13 @@ def main():
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 @@ def main():
# 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 = {

View File

@@ -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()