blob: b692be511065e920e1a7356c8ec922c9cf65961a [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
Joe Gregorio48d361f2010-08-18 13:19:21 -040014
15from apiclient.discovery import build
16
17import httplib2
Joe Gregorio845a5452010-09-08 13:50:34 -040018import pickle
Joe Gregorio48d361f2010-08-18 13:19:21 -040019
20
21def main():
Joe Gregorioa2f56e72010-09-09 15:15:56 -040022 f = open("buzz.dat", "r")
Joe Gregorio845a5452010-09-08 13:50:34 -040023 credentials = pickle.loads(f.read())
24 f.close()
25
26 http = httplib2.Http()
27 http = credentials.authorize(http)
28
Joe Gregorio41cf7972010-08-18 15:21:06 -040029 p = build("buzz", "v1", http=http)
Joe Gregorio48d361f2010-08-18 13:19:21 -040030 activities = p.activities()
Joe Gregorioc5c5a372010-09-22 11:42:32 -040031 activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
Joe Gregorio48d361f2010-08-18 13:19:21 -040032 print activitylist['items'][0]['title']
Joe Gregorioc5c5a372010-09-22 11:42:32 -040033 activitylist = activities.list_next(activitylist).execute()
34 print activitylist['items'][0]['title']
35
Joe Gregorio48d361f2010-08-18 13:19:21 -040036 activities.insert(userId='@me', body={
37 'title': 'Testing insert',
38 'object': {
Joe Gregorio41cf7972010-08-18 15:21:06 -040039 'content': u'Just a short note to show that insert is working. ☄',
Joe Gregorio48d361f2010-08-18 13:19:21 -040040 'type': 'note'}
41 }
Joe Gregorio5f087cf2010-09-20 16:08:07 -040042 ).execute()
Joe Gregorio48d361f2010-08-18 13:19:21 -040043
44if __name__ == '__main__':
45 main()