[mq]: oauth2
diff --git a/samples/oauth2/appengine/apiclient b/samples/oauth2/appengine/apiclient
new file mode 120000
index 0000000..f53af07
--- /dev/null
+++ b/samples/oauth2/appengine/apiclient
@@ -0,0 +1 @@
+../../../apiclient/
\ No newline at end of file
diff --git a/samples/oauth2/appengine/app.yaml b/samples/oauth2/appengine/app.yaml
new file mode 100644
index 0000000..03bdf81
--- /dev/null
+++ b/samples/oauth2/appengine/app.yaml
@@ -0,0 +1,16 @@
+application: m-buzz
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /static
+ static_dir: static
+
+- url: /google8f1adb368b7bd14c.html
+ upload: google8f1adb368b7bd14c.html
+ static_files: static/google8f1adb368b7bd14c.html
+
+- url: .*
+ script: main.py
+
diff --git a/samples/oauth2/appengine/httplib2 b/samples/oauth2/appengine/httplib2
new file mode 120000
index 0000000..69b02ef
--- /dev/null
+++ b/samples/oauth2/appengine/httplib2
@@ -0,0 +1 @@
+../../../httplib2/
\ No newline at end of file
diff --git a/samples/oauth2/appengine/index.yaml b/samples/oauth2/appengine/index.yaml
new file mode 100644
index 0000000..a3b9e05
--- /dev/null
+++ b/samples/oauth2/appengine/index.yaml
@@ -0,0 +1,11 @@
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run. If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED"). If you want to manage some indexes
+# manually, move them above the marker line. The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
diff --git a/samples/oauth2/appengine/main.py b/samples/oauth2/appengine/main.py
new file mode 100644
index 0000000..1c0676c
--- /dev/null
+++ b/samples/oauth2/appengine/main.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+
+
+import httplib2
+import logging
+import os
+import pickle
+
+from apiclient.discovery import build
+from oauth2client.appengine import CredentialsProperty
+from oauth2client.appengine import StorageByKeyName
+from oauth2client.client import OAuth2WebServerFlow
+from google.appengine.api import memcache
+from google.appengine.api import users
+from google.appengine.ext import db
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import template
+from google.appengine.ext.webapp import util
+from google.appengine.ext.webapp.util import login_required
+
+
+class Credentials(db.Model):
+ credentials = CredentialsProperty()
+
+
+class MainHandler(webapp.RequestHandler):
+
+ @login_required
+ def get(self):
+ user = users.get_current_user()
+ credentials = StorageByKeyName(Credentials, user.user_id(), 'credentials').get()
+
+ if credentials:
+ http = httplib2.Http()
+ http = credentials.authorize(http)
+ p = build("buzz", "v1", http=http)
+ activities = p.activities()
+ activitylist = activities.list(scope='@consumption',
+ userId='@me').execute()
+ path = os.path.join(os.path.dirname(__file__), 'welcome.html')
+ logout = users.create_logout_url('/')
+ self.response.out.write(
+ template.render(
+ path, {'activitylist': activitylist,
+ 'logout': logout
+ }))
+ else:
+ flow = OAuth2WebServerFlow(
+ client_id='anonymous',
+ client_secret='anonymous',
+ scope='https://www.googleapis.com/auth/buzz',
+ user_agent='buzz-cmdline-sample/1.0',
+ domain='anonymous',
+ xoauth_displayname='Google App Engine Example App')
+
+ callback = self.request.relative_url('/auth_return')
+ authorize_url = flow.step1_get_authorize_url(callback)
+ memcache.set(user.user_id(), pickle.dumps(flow))
+ self.redirect(authorize_url)
+
+
+class OAuthHandler(webapp.RequestHandler):
+
+ @login_required
+ def get(self):
+ user = users.get_current_user()
+ flow = pickle.loads(memcache.get(user.user_id()))
+ if flow:
+ credentials = flow.step2_exchange(self.request.params)
+ StorageByKeyName(Credentials, user.user_id(), 'credentials').put(credentials)
+ self.redirect("/")
+ else:
+ pass
+
+
+def main():
+ application = webapp.WSGIApplication(
+ [
+ ('/', MainHandler),
+ ('/auth_return', OAuthHandler)
+ ],
+ debug=True)
+ util.run_wsgi_app(application)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/samples/oauth2/appengine/oauth2client b/samples/oauth2/appengine/oauth2client
new file mode 120000
index 0000000..0a1ec33
--- /dev/null
+++ b/samples/oauth2/appengine/oauth2client
@@ -0,0 +1 @@
+../../../oauth2client/
\ No newline at end of file
diff --git a/samples/oauth2/appengine/simplejson b/samples/oauth2/appengine/simplejson
new file mode 120000
index 0000000..eeaa2f0
--- /dev/null
+++ b/samples/oauth2/appengine/simplejson
@@ -0,0 +1 @@
+../../../simplejson/
\ No newline at end of file
diff --git a/samples/oauth2/appengine/uritemplate b/samples/oauth2/appengine/uritemplate
new file mode 120000
index 0000000..5952908
--- /dev/null
+++ b/samples/oauth2/appengine/uritemplate
@@ -0,0 +1 @@
+../../../uritemplate/
\ No newline at end of file
diff --git a/samples/oauth2/appengine/welcome.html b/samples/oauth2/appengine/welcome.html
new file mode 100644
index 0000000..da40a16
--- /dev/null
+++ b/samples/oauth2/appengine/welcome.html
@@ -0,0 +1,29 @@
+<html>
+ <head>
+ <title>Buzz Stuff</title>
+ <style type=text/css>
+ td { vertical-align: top; padding: 0.5em }
+ img { border:0 }
+ </style>
+ </head>
+ <body>
+ <p><a href="{{ logout }}">Logout</a></p>
+ <table border=0>
+ {% for item in activitylist.items %}
+ <tr valign=top>
+ <td>
+ <a href="{{ item.actor.profileUrl }}"><img
+ src="{{ item.actor.thumbnailUrl }}"></a><br>
+ <a href="{{ item.actor.profileUrl }}">{{ item.actor.name }}</a></td>
+ <td>
+ {{ item.object.content }}
+ </td>
+ <td>
+ <a href="{{ item.object.links.alternate.0.href }}"><img
+ src="/static/go.png"></a>
+ </td>
+ </tr>
+ {% endfor %}
+ </table>
+ </body>
+</html>
diff --git a/samples/oauth2/buzz/buzz.py b/samples/oauth2/buzz/buzz.py
new file mode 100644
index 0000000..7df6c72
--- /dev/null
+++ b/samples/oauth2/buzz/buzz.py
@@ -0,0 +1,71 @@
+#!/usr/bin/python2.4
+# -*- coding: utf-8 -*-
+#
+# Copyright 2010 Google Inc. All Rights Reserved.
+
+"""Simple command-line example for Buzz.
+
+Command-line application that retrieves the users
+latest content and then adds a new entry.
+"""
+
+__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+
+from apiclient.discovery import build
+from oauth2client.file import Storage
+
+import httplib2
+import pickle
+import pprint
+
+# Uncomment the next line to get very detailed logging
+#httplib2.debuglevel = 4
+
+
+def main():
+ credentials = Storage('buzz.dat').get()
+
+ http = httplib2.Http()
+ http = credentials.authorize(http)
+
+ 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()
+ print "Retrieved the first two activities"
+
+ # Retrieve the next two activities
+ if activitylist:
+ activitylist = activities.list_next(activitylist).execute()
+ print "Retrieved the next two activities"
+
+ # Add a new activity
+ new_activity_body = {
+ "data": {
+ 'title': 'Testing insert',
+ 'object': {
+ '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()
+
+ # Add a comment to that activity
+ comment_body = {
+ "data": {
+ "content": "This is a comment"
+ }
+ }
+ item = activitylist['items'][0]
+ comment = p.comments().insert(
+ userId=item['actor']['id'], postId=item['id'], body=comment_body
+ ).execute()
+ print 'Added a comment to the new activity'
+ pprint.pprint(comment)
+
+if __name__ == '__main__':
+ main()
diff --git a/samples/oauth2/buzz/web_server_dance.py b/samples/oauth2/buzz/web_server_dance.py
new file mode 100644
index 0000000..7b94103
--- /dev/null
+++ b/samples/oauth2/buzz/web_server_dance.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2010 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Do the OAuth 2.0 Web Server dance.
+
+Do the OAuth 2.0 Web Server dance for
+a command line application. Store the generated
+credentials in a common file that is used by
+other example apps in the same directory.
+"""
+
+__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+
+from oauth2client.client import OAuth2WebServerFlow
+from oauth2client.tools import run
+
+flow = OAuth2WebServerFlow(
+ client_id='anonymous',
+ client_secret='anonymous',
+ scope='https://www.googleapis.com/auth/buzz',
+ user_agent='buzz-cmdline-sample/1.0',
+ domain='anonymous',
+ xoauth_displayname='Buzz Client Example App'
+ )
+
+run(flow, 'buzz.dat')
diff --git a/samples/oauth2/moderator/moderator.py b/samples/oauth2/moderator/moderator.py
new file mode 100644
index 0000000..9a3dbb2
--- /dev/null
+++ b/samples/oauth2/moderator/moderator.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python2.4
+# -*- coding: utf-8 -*-
+#
+# Copyright 2010 Google Inc. All Rights Reserved.
+
+"""Simple command-line example for Buzz.
+
+Command-line application that retrieves the users
+latest content and then adds a new entry.
+"""
+
+__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+
+
+from apiclient.discovery import build
+from oauth2client.file import Storage
+
+import httplib2
+
+# Uncomment to get low level HTTP logging
+#httplib2.debuglevel = 4
+
+# Uncomment to get logging
+#import logging
+#logging.basicConfig(level=logging.DEBUG)
+
+
+def main():
+ credentials = Storage('moderator.dat').get()
+
+ http = httplib2.Http()
+ http = credentials.authorize(http)
+
+ p = build("moderator", "v1", http=http)
+
+ series_body = {
+ "data": {
+ "description": "Share and rank tips for eating healthy and cheap!",
+ "name": "Eating Healthy & Cheap",
+ "videoSubmissionAllowed": False
+ }
+ }
+ series = p.series().insert(body=series_body).execute()
+ print "Created a new series"
+
+ topic_body = {
+ "data": {
+ "description": "Share your ideas on eating healthy!",
+ "name": "Ideas",
+ "presenter": "liz"
+ }
+ }
+ topic = p.topics().insert(seriesId=series['id']['seriesId'],
+ body=topic_body).execute()
+ print "Created a new topic"
+
+ submission_body = {
+ "data": {
+ "attachmentUrl": "http://www.youtube.com/watch?v=1a1wyc5Xxpg",
+ "attribution": {
+ "displayName": "Bashan",
+ "location": "Bainbridge Island, WA"
+ },
+ "text": "Charlie Ayers @ Google"
+ }
+ }
+ submission = p.submissions().insert(seriesId=topic['id']['seriesId'],
+ topicId=topic['id']['topicId'], body=submission_body).execute()
+ print "Inserted a new submisson on the topic"
+
+ vote_body = {
+ "data": {
+ "vote": "PLUS"
+ }
+ }
+ p.votes().insert(seriesId=topic['id']['seriesId'],
+ submissionId=submission['id']['submissionId'],
+ body=vote_body)
+ print "Voted on the submission"
+
+
+if __name__ == '__main__':
+ main()
diff --git a/samples/oauth2/moderator/web_server_dance.py b/samples/oauth2/moderator/web_server_dance.py
new file mode 100644
index 0000000..f478341
--- /dev/null
+++ b/samples/oauth2/moderator/web_server_dance.py
@@ -0,0 +1,35 @@
+# Copyright (C) 2010 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Do the OAuth 2.0 Web Server dance.
+
+Do the OAuth 2.0 Web Server dance for
+a command line application. Store the generated
+credentials in a common file that is used by
+other example apps in the same directory.
+"""
+
+__author__ = 'jcgregorio@google.com (Joe Gregorio)'
+
+from oauth2client.client import OAuth2WebServerFlow
+from oauth2client.tools import run
+
+flow = OAuth2WebServerFlow(
+ client_id='anonymous',
+ client_secret='anonymous',
+ scope='https://www.googleapis.com/auth/moderator',
+ user_agent='moderator-cmdline-sample/1.0',
+ xoauth_displayname='Moderator Client Example App')
+
+run(flow, 'moderator.dat')