blob: f24c0325403ab5fdf2e62fcaf2d7c4861c5ad007 [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 Gregorio59cd9512010-10-04 12:46:46 -040022# httplib2.debuglevel = 4
Joe Gregorio845a5452010-09-08 13:50:34 -040023import pickle
ade@google.comcfc39d12010-09-27 22:31:46 +010024import pprint
Joe Gregorio48d361f2010-08-18 13:19:21 -040025
26def main():
Joe Gregorioa2f56e72010-09-09 15:15:56 -040027 f = open("buzz.dat", "r")
Joe Gregorio845a5452010-09-08 13:50:34 -040028 credentials = pickle.loads(f.read())
29 f.close()
30
31 http = httplib2.Http()
32 http = credentials.authorize(http)
33
Joe Gregorio59cd9512010-10-04 12:46:46 -040034 p = build("buzz", "v1", http=http)
Joe Gregorio48d361f2010-08-18 13:19:21 -040035 activities = p.activities()
Joe Gregorioc5c5a372010-09-22 11:42:32 -040036 activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
Joe Gregorio48d361f2010-08-18 13:19:21 -040037 print activitylist['items'][0]['title']
Joe Gregorioc5c5a372010-09-22 11:42:32 -040038 activitylist = activities.list_next(activitylist).execute()
39 print activitylist['items'][0]['title']
40
ade@google.comcfc39d12010-09-27 22:31:46 +010041 activity = activities.insert(userId='@me', body={
Joe Gregorio48d361f2010-08-18 13:19:21 -040042 'title': 'Testing insert',
43 'object': {
Joe Gregorio41cf7972010-08-18 15:21:06 -040044 'content': u'Just a short note to show that insert is working. ☄',
Joe Gregorio48d361f2010-08-18 13:19:21 -040045 'type': 'note'}
46 }
Joe Gregorio5f087cf2010-09-20 16:08:07 -040047 ).execute()
ade@google.comcfc39d12010-09-27 22:31:46 +010048 pprint.pprint(activity)
49 print
50 print 'Just created: ', activity['links']['alternate'][0]['href']
Joe Gregorio48d361f2010-08-18 13:19:21 -040051
52if __name__ == '__main__':
53 main()