blob: 14b5ea1b5441c4359a62ea8983ac97ce87f993b7 [file] [log] [blame]
jcgregorio@google.come3c8b6d2010-10-07 19:34:54 -04001#!/usr/bin/python2.4
2# -*- coding: utf-8 -*-
3#
4# Copyright 2010 Google Inc. All Rights Reserved.
5
6"""Simple command-line example for Buzz.
7
8Command-line application that retrieves the users
9latest content and then adds a new entry.
10"""
11
12__author__ = 'jcgregorio@google.com (Joe Gregorio)'
13
14from apiclient.discovery import build
15
16import httplib2
17import pickle
18import pprint
19
20# Uncomment the next line to get very detailed logging
21# httplib2.debuglevel = 4
22
23def main():
24 f = open("buzz.dat", "r")
25 credentials = pickle.loads(f.read())
26 f.close()
27
28 http = httplib2.Http()
29 http = credentials.authorize(http)
30
31 p = build("buzz", "v1", http=http)
32 activities = p.activities()
33
34 # Retrieve the first two activities
35 activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
36 print "Retrieved the first two activities"
37
38 # Retrieve the next two activities
39 activitylist = activities.list_next(activitylist).execute()
40 print "Retrieved the next two activities"
41
42 # Add a new activity
43 new_activity_body = {
44 'title': 'Testing insert',
45 'object': {
46 'content': u'Just a short note to show that insert is working. ☄',
47 'type': 'note'}
48 }
49 activity = activities.insert(userId='@me', body=new_activity_body).execute()
50 print "Added a new activity"
51
52 activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
53
54 # Add a comment to that activity
55 comment_body = {
56 "content": "This is a comment"
57 }
58 item = activitylist['items'][0]
59 comment = p.comments().insert(
60 userId=item['actor']['id'], postId=item['id'], body=comment_body
61 ).execute()
62 print 'Added a comment to the new activity'
63 pprint.pprint(comment)
64
65if __name__ == '__main__':
66 main()