Cleaned up OAuth 2.0 support fully using Storage() and updating samples.
diff --git a/samples/oauth2/buzz/buzz.py b/samples/oauth2/buzz/buzz.py
index 7df6c72..fe30a32 100644
--- a/samples/oauth2/buzz/buzz.py
+++ b/samples/oauth2/buzz/buzz.py
@@ -11,28 +11,43 @@
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
-from apiclient.discovery import build
-from oauth2client.file import Storage
-
import httplib2
import pickle
import pprint
+from apiclient.discovery import build
+from oauth2client.file import Storage
+from oauth2client.client import OAuth2WebServerFlow
+from oauth2client.tools import run
+
# Uncomment the next line to get very detailed logging
#httplib2.debuglevel = 4
def main():
- credentials = Storage('buzz.dat').get()
+ storage = Storage('buzz.dat')
+ credentials = storage.get()
+ if not credentials:
+ flow = OAuth2WebServerFlow(
+ client_id='433807057907.apps.googleusercontent.com',
+ client_secret='jigtZpMApkRxncxikFpR+SFg',
+ scope='https://www.googleapis.com/auth/buzz',
+ user_agent='buzz-cmdline-sample/1.0',
+ domain='anonymous',
+ xoauth_displayname='Buzz Client Example App'
+ )
+ credentials = run(flow, storage)
http = httplib2.Http()
http = credentials.authorize(http)
- p = build("buzz", "v1", http=http, developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
+ p = build("buzz", "v1", http=http,
+ developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
activities = p.activities()
# Retrieve the first two activities
- activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
+ activitylist = activities.list(
+ max_results='2', scope='@self', userId='@me').execute()
print "Retrieved the first two activities"
# Retrieve the next two activities
@@ -45,14 +60,16 @@
"data": {
'title': 'Testing insert',
'object': {
- 'content': u'Just a short note to show that insert is working. ☄',
+ 'content':
+ u'Just a short note to show that insert is working. ☄',
'type': 'note'}
}
}
activity = activities.insert(userId='@me', body=new_activity_body).execute()
print "Added a new activity"
- activitylist = activities.list(max_results='2', scope='@self', userId='@me').execute()
+ activitylist = activities.list(
+ max_results='2', scope='@self', userId='@me').execute()
# Add a comment to that activity
comment_body = {