Added Google URL Shortener API sample
This commit is contained in:
@@ -74,6 +74,7 @@ class MainHandler(webapp.RequestHandler):
|
|||||||
<li><a href='/translate/v2'>translate</a>
|
<li><a href='/translate/v2'>translate</a>
|
||||||
<li><a href='/prediction/v1.1'>prediction</a>
|
<li><a href='/prediction/v1.1'>prediction</a>
|
||||||
<li><a href='/shopping/v1'>shopping</a>
|
<li><a href='/shopping/v1'>shopping</a>
|
||||||
|
<li><a href='/urlshortener/v1'>urlshortener</a>
|
||||||
</ul>
|
</ul>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|||||||
@@ -29,11 +29,13 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(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()
|
activities = p.activities()
|
||||||
|
|
||||||
# Retrieve the first two 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"
|
print "Retrieved the first two activities"
|
||||||
|
|
||||||
# Retrieve the next two activities
|
# Retrieve the next two activities
|
||||||
@@ -53,7 +55,8 @@ def main():
|
|||||||
activity = activities.insert(userId='@me', body=new_activity_body).execute()
|
activity = activities.insert(userId='@me', body=new_activity_body).execute()
|
||||||
print "Added a new activity"
|
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
|
# Add a comment to that activity
|
||||||
comment_body = {
|
comment_body = {
|
||||||
|
|||||||
41
samples/urlshortener/main.py
Normal file
41
samples/urlshortener/main.py
Normal 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()
|
||||||
Reference in New Issue
Block a user