Skip to content

Commit 88243be

Browse files
committed
Added Google URL Shortener API sample
1 parent f93b13d commit 88243be

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

samples/api-python-client-doc/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def get(self):
7474
<li><a href='/translate/v2'>translate</a>
7575
<li><a href='/prediction/v1.1'>prediction</a>
7676
<li><a href='/shopping/v1'>shopping</a>
77+
<li><a href='/urlshortener/v1'>urlshortener</a>
7778
</ul>
7879
""")
7980

samples/buzz/buzz.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ def main():
2929
http = httplib2.Http()
3030
http = credentials.authorize(http)
3131

32-
p = build("buzz", "v1", http=http, developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
32+
p = build("buzz", "v1", http=http,
33+
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
3334
activities = p.activities()
3435

3536
# Retrieve the first two activities
36-
activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
37+
activitylist = activities.list(
38+
max_results='2', scope='@self', userId='@me').execute()
3739
print "Retrieved the first two activities"
3840

3941
# Retrieve the next two activities
@@ -44,16 +46,17 @@ def main():
4446
# Add a new activity
4547
new_activity_body = {
4648
"data": {
47-
'title': 'Testing insert',
48-
'object': {
49-
'content': u'Just a short note to show that insert is working. ☄',
50-
'type': 'note'}
51-
}
49+
'title': 'Testing insert',
50+
'object': {
51+
'content': u'Just a short note to show that insert is working. ☄',
52+
'type': 'note'}
53+
}
5254
}
5355
activity = activities.insert(userId='@me', body=new_activity_body).execute()
5456
print "Added a new activity"
5557

56-
activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
58+
activitylist = activities.list(
59+
max_results='2', scope='@self', userId='@me').execute()
5760

5861
# Add a comment to that activity
5962
comment_body = {

samples/urlshortener/main.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/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+
8+
Command-line application that shortens a URL.
9+
"""
10+
11+
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
12+
13+
from apiclient.discovery import build
14+
15+
import pprint
16+
17+
# Uncomment the next two lines to get very detailed logging
18+
#import httplib2
19+
#httplib2.debuglevel = 4
20+
21+
22+
def 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+
40+
if __name__ == '__main__':
41+
main()

0 commit comments

Comments
 (0)