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