Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 1 | #!/usr/bin/python2.4 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # |
| 4 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 5 | |
Joe Gregorio | 845a545 | 2010-09-08 13:50:34 -0400 | [diff] [blame] | 6 | """Simple command-line example for Buzz. |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 7 | |
Joe Gregorio | 845a545 | 2010-09-08 13:50:34 -0400 | [diff] [blame] | 8 | Command-line application that retrieves the users |
| 9 | latest content and then adds a new entry. |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 10 | """ |
| 11 | |
| 12 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 13 | |
ade@google.com | cfc39d1 | 2010-09-27 22:31:46 +0100 | [diff] [blame] | 14 | # Enable this sample to be run from the top-level directory |
| 15 | import os |
| 16 | import sys |
| 17 | sys.path.insert(0, os.getcwd()) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 18 | |
| 19 | from apiclient.discovery import build |
| 20 | |
| 21 | import httplib2 |
Joe Gregorio | 59cd951 | 2010-10-04 12:46:46 -0400 | [diff] [blame] | 22 | # httplib2.debuglevel = 4 |
Joe Gregorio | 845a545 | 2010-09-08 13:50:34 -0400 | [diff] [blame] | 23 | import pickle |
ade@google.com | cfc39d1 | 2010-09-27 22:31:46 +0100 | [diff] [blame] | 24 | import pprint |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 25 | |
| 26 | def main(): |
Joe Gregorio | a2f56e7 | 2010-09-09 15:15:56 -0400 | [diff] [blame] | 27 | f = open("buzz.dat", "r") |
Joe Gregorio | 845a545 | 2010-09-08 13:50:34 -0400 | [diff] [blame] | 28 | credentials = pickle.loads(f.read()) |
| 29 | f.close() |
| 30 | |
| 31 | http = httplib2.Http() |
| 32 | http = credentials.authorize(http) |
| 33 | |
Joe Gregorio | 59cd951 | 2010-10-04 12:46:46 -0400 | [diff] [blame] | 34 | p = build("buzz", "v1", http=http) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 35 | activities = p.activities() |
Joe Gregorio | c5c5a37 | 2010-09-22 11:42:32 -0400 | [diff] [blame] | 36 | activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute() |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 37 | print activitylist['items'][0]['title'] |
Joe Gregorio | c5c5a37 | 2010-09-22 11:42:32 -0400 | [diff] [blame] | 38 | activitylist = activities.list_next(activitylist).execute() |
| 39 | print activitylist['items'][0]['title'] |
| 40 | |
ade@google.com | cfc39d1 | 2010-09-27 22:31:46 +0100 | [diff] [blame] | 41 | activity = activities.insert(userId='@me', body={ |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 42 | 'title': 'Testing insert', |
| 43 | 'object': { |
Joe Gregorio | 41cf797 | 2010-08-18 15:21:06 -0400 | [diff] [blame] | 44 | 'content': u'Just a short note to show that insert is working. ☄', |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 45 | 'type': 'note'} |
| 46 | } |
Joe Gregorio | 5f087cf | 2010-09-20 16:08:07 -0400 | [diff] [blame] | 47 | ).execute() |
ade@google.com | cfc39d1 | 2010-09-27 22:31:46 +0100 | [diff] [blame] | 48 | pprint.pprint(activity) |
| 49 | print |
| 50 | print 'Just created: ', activity['links']['alternate'][0]['href'] |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 51 | |
| 52 | if __name__ == '__main__': |
| 53 | main() |