blob: c7f9990efeb657a81532bca160b0c1c9da2c697f [file] [log] [blame]
Joe Gregorio48d361f2010-08-18 13:19:21 -04001#!/usr/bin/python2.4
2# -*- coding: utf-8 -*-
3#
4# Copyright 2010 Google Inc. All Rights Reserved.
5
Joe Gregorio845a5452010-09-08 13:50:34 -04006"""Simple command-line example for Buzz.
Joe Gregorio48d361f2010-08-18 13:19:21 -04007
Joe Gregorio845a5452010-09-08 13:50:34 -04008Command-line application that retrieves the users
9latest content and then adds a new entry.
Joe Gregorio48d361f2010-08-18 13:19:21 -040010"""
11
12__author__ = 'jcgregorio@google.com (Joe Gregorio)'
13
ade@google.comcfc39d12010-09-27 22:31:46 +010014# Enable this sample to be run from the top-level directory
15import os
16import sys
17sys.path.insert(0, os.getcwd())
Joe Gregorio48d361f2010-08-18 13:19:21 -040018
19from apiclient.discovery import build
20
21import httplib2
Joe Gregorio845a5452010-09-08 13:50:34 -040022import pickle
ade@google.comcfc39d12010-09-27 22:31:46 +010023import pprint
Joe Gregorio48d361f2010-08-18 13:19:21 -040024
25def main():
Joe Gregorioa2f56e72010-09-09 15:15:56 -040026 f = open("buzz.dat", "r")
Joe Gregorio845a5452010-09-08 13:50:34 -040027 credentials = pickle.loads(f.read())
28 f.close()
29
30 http = httplib2.Http()
31 http = credentials.authorize(http)
32
Joe Gregorio41cf7972010-08-18 15:21:06 -040033 p = build("buzz", "v1", http=http)
Joe Gregorio48d361f2010-08-18 13:19:21 -040034 activities = p.activities()
Joe Gregorioc5c5a372010-09-22 11:42:32 -040035 activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
Joe Gregorio48d361f2010-08-18 13:19:21 -040036 print activitylist['items'][0]['title']
Joe Gregorioc5c5a372010-09-22 11:42:32 -040037 activitylist = activities.list_next(activitylist).execute()
38 print activitylist['items'][0]['title']
39
ade@google.comcfc39d12010-09-27 22:31:46 +010040 activity = activities.insert(userId='@me', body={
Joe Gregorio48d361f2010-08-18 13:19:21 -040041 'title': 'Testing insert',
42 'object': {
Joe Gregorio41cf7972010-08-18 15:21:06 -040043 'content': u'Just a short note to show that insert is working. ☄',
Joe Gregorio48d361f2010-08-18 13:19:21 -040044 'type': 'note'}
45 }
Joe Gregorio5f087cf2010-09-20 16:08:07 -040046 ).execute()
ade@google.comcfc39d12010-09-27 22:31:46 +010047 pprint.pprint(activity)
48 print
49 print 'Just created: ', activity['links']['alternate'][0]['href']
Joe Gregorio48d361f2010-08-18 13:19:21 -040050
51if __name__ == '__main__':
52 main()