Hi Eric, it worked. I do get another error now:
Traceback (most recent call last):
File "C:\Program
Files\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line
701, in __call__
handler.get(*groups)
File "C:\xampplite\engineapp1\helloworldnew\main.py", line 35, in get
event = self.get_next_event(user)
File "C:\xampplite\engineapp1\helloworldnew\main.py", line 75, in
get_next_event
feed = client.CalendarQuery(query)
File "C:\xampplite\engineapp1\helloworldnew\gdata\calendar\service.py", line
126, in CalendarQuery
converter=gdata.calendar.CalendarEventFeedFromString)
File "C:\xampplite\engineapp1\helloworldnew\gdata\calendar\service.py", line
118, in Query
result = self.Get(uri, converter=converter)
File "C:\xampplite\engineapp1\helloworldnew\gdata\service.py", line 1108, in
Get
'reason': server_response.reason, 'body': result_body}
RequestError: {'status': 401, 'body': '<HTML>\n<HEAD>\n<TITLE>Unknown
authorization header</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF"
TEXT="#000000">\n<H1>Unknown authorization header</H1>\n<H2>Error
401</H2>\n</BODY>\n</HTML>\n', 'reason':
and my code looks like this:
#!/usr/bin/env python
#
# Copyright 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.
#
import os, re
from datetime import datetime
from urlparse import urlparse
import gdata.auth
import gdata.calendar.service
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp import util
class MainHandler(webapp.RequestHandler):
def get(self):
template_values = {}
user = users.get_current_user()
if user and self.check_email(user):
greeting = ('Hello %s (%s)!)' %
(user.email(), user.nickname()))
event = self.get_next_event(user)
if event:
template_values['title'] = event.title.text
template_values['start'] = event.when[0].start_time
template_values['end'] = event.when[0].end_time
template_values['where'] = event.where[0].value_string
template_values['desc'] = event.content.text
else:
greeting = 'You need to log in!'
template_values['greeting'] = greeting
path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
self.response.out.write(template.render(path, template_values))
def check_email(self, user):
"""Performs basic validation of the supplied email address as outlined
in http://code.google.com/googleapps/marketplace/best_practices.html
"""
domain = urlparse(user.federated_identity()).hostname if
user.federated_identity() else "stingerit.com"
m = re.search('.*@' + domain, user.email())
if m:
return True
else:
return False
def get_next_event(self, user):
"""Uses two-legged OAuth to retrieve the user's next Calendar event."""
CONSUMER_KEY = "107975625810.apps.googleusercontent.com"
CONSUMER_SECRET = "gVdWZAMrxiIzgJgybpQxxxxx"
SIG_METHOD = gdata.auth.OAuthSignatureMethod.HMAC_SHA1
client =
gdata.calendar.service.CalendarService(source='myCompany-helloworld')
client.SetOAuthInputParameters(SIG_METHOD, CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET,
two_legged_oauth=True,
requestor_id=user.email())
query = gdata.calendar.service.CalendarEventQuery('default', 'private',
'full')
query.start_min = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
query.sortorder = 'ascending'
query.orderby = 'starttime'
query.max_results = 1
feed = client.CalendarQuery(query)
if len(feed.entry):
return feed.entry[0]
else:
return None
class OpenIDHandler(webapp.RequestHandler):
def get(self):
"""Begins the OpenID flow and begins Google Apps discovery for the
supplied domain."""
self.redirect(users.create_login_url(dest_url='http://my-app.appspot.com/',
_auth_domain=None,
federated_identity=self.request.get('domain')))
def main():
application = webapp.WSGIApplication([('/', MainHandler),
('/_ah/login_required', OpenIDHandler)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
What is it now?
Thank you very much for your help.
--
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html