Переходя от AuthSub к OAuth, я думаю, что постепенно начинаю понимать процесс.
Этот бросил мне ошибку, хотя:
#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template
from gdata.calendar import service
import gdata
from gdata.alt.appengine import run_on_appengine
from google.appengine.api import users
from google.appengine.ext import db
from gdata.auth import OAuthSignatureMethod, OAuthToken, OAuthInputParams
import urllib
import simplejson
import gdata.gauth
from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError
SCOPES = 'https://www.google.com/calendar/feeds/' # in this case just one, but for future reference, just concatenate different scopes with a space in between
CONSUMER_KEY = 'jmm-timeline.appspot.com'
CONSUMER_SECRET = 'consumer secret key, here'
SIG_METHOD = gdata.auth.OAuthSignatureMethod.RSA_SHA1
f = open('remotekey.pem')
RSA_KEY = f.read()
f.close()
# Incomplete bibliography
# http://www.youtube.com/watch?v=bfgO-LXGpTM
# http://code.google.com/appengine/articles/python/retrieving_gdata_feeds.html
class BasePage(webapp.RequestHandler):
title = "Joshua's Construction Zone"
def write_page_header(self):
self.response.out.write(template.render('templates/header.html', {'title': self.title}))
def write_page_footer(self):
self.response.out.write(template.render('templates/footer.html', {}))
class MainHandler(BasePage):
def get(self):
self.write_page_header()
try:
client = gdata.calendar.service.CalendarService(source='jmm-timeline-v1')
run_on_appengine(client)
client.SetOAuthInputParameters(gdata.auth.OAuthSignatureMethod.RSA_SHA1, consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET, rsa_key=RSA_KEY)
req_token = client.FetchOAuthRequestToken(SCOPES)
oauth_callback_url = 'http://jmm-timeline.appspot.com/handle_authorized_request_token'
oauth_authorization_url = client.GenerateOAuthAuthorizationURL(callback_url=oauth_callback_url)
self.response.out.write(template.render('templates/authorization_prompt.html', { 'authorization_url': oauth_authorization_url }))
except CapabilityDisabledError, e:
self.response.out.write(template.render('templates/content/maintenance.html'))
self.write_page_footer()
class HandleAuthorizedRequestToken(BasePage):
def get(self):
self.write_page_header()
client = gdata.calendar.service.CalendarService('jmm-timeline-2');
run_on_appengine(client)
self.write_page_footer()
def main():
application = webapp.WSGIApplication([('/', MainHandler), ('/handle_authorized_request_token', HandleAuthorizedRequestToken)], debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
Похоже, что gdata пытается прочитать мою строку RSA_KEY, и я получаю трассировку стека:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__
handler.get(*groups)
File "C:\Users\Joshua\appengineapps\jmm-timeline\main.py", line 52, in get
req_token = client.FetchOAuthRequestToken(SCOPES)
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\service.py", line 415, in FetchOAuthRequestToken
extra_parameters=extra_parameters)
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\auth.py", line 217, in GenerateOAuthRequestTokenUrl
oauth_input_params.GetConsumer(), None)
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\oauth\__init__.py", line 171, in sign_request
self.set_parameter('oauth_signature', self.build_signature(signature_method, consumer, token))
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\oauth\__init__.py", line 175, in build_signature
return signature_method.build_signature(self, consumer, token)
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\oauth\rsa.py", line 55, in build_signature
privatekey = keyfactory.parsePrivateKey(cert)
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\tlslite\utils\keyfactory.py", line 203, in parsePrivateKey
return parseXMLKey(s, private=True)
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\tlslite\utils\keyfactory.py", line 79, in parseXMLKey
key = Python_RSAKey.parseXML(s)
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\tlslite\utils\Python_RSAKey.py", line 137, in parseXML
element = xmltools.parseAndStripWhitespace(s)
File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\tlslite\utils\xmltools.py", line 30, in parseAndStripWhitespace
raise SyntaxError(str(e))
SyntaxError: syntax error: line 1, column 0