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 | |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 14 | |
| 15 | from apiclient.discovery import build |
| 16 | |
| 17 | import httplib2 |
Joe Gregorio | 845a545 | 2010-09-08 13:50:34 -0400 | [diff] [blame] | 18 | import pickle |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 19 | |
| 20 | |
| 21 | def main(): |
Joe Gregorio | a2f56e7 | 2010-09-09 15:15:56 -0400 | [diff] [blame] | 22 | f = open("buzz.dat", "r") |
Joe Gregorio | 845a545 | 2010-09-08 13:50:34 -0400 | [diff] [blame] | 23 | credentials = pickle.loads(f.read()) |
| 24 | f.close() |
| 25 | |
| 26 | http = httplib2.Http() |
| 27 | http = credentials.authorize(http) |
| 28 | |
Joe Gregorio | 41cf797 | 2010-08-18 15:21:06 -0400 | [diff] [blame] | 29 | p = build("buzz", "v1", http=http) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 30 | activities = p.activities() |
Joe Gregorio | 5f087cf | 2010-09-20 16:08:07 -0400 | [diff] [blame^] | 31 | activitylist = activities.list(scope='@self', userId='@me').execute() |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 32 | print activitylist['items'][0]['title'] |
| 33 | activities.insert(userId='@me', body={ |
| 34 | 'title': 'Testing insert', |
| 35 | 'object': { |
Joe Gregorio | 41cf797 | 2010-08-18 15:21:06 -0400 | [diff] [blame] | 36 | 'content': u'Just a short note to show that insert is working. ☄', |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 37 | 'type': 'note'} |
| 38 | } |
Joe Gregorio | 5f087cf | 2010-09-20 16:08:07 -0400 | [diff] [blame^] | 39 | ).execute() |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 40 | |
| 41 | if __name__ == '__main__': |
| 42 | main() |