Using GAE / Decorators指南告诉我“您需要向您的应用程序添加一个特定的 URL 处理程序来处理从授权服务器到您的应用程序的重定向”:
def main():
application = webapp.WSGIApplication(
[
('/', MainHandler),
('/about', AboutHandler),
(decorator.callback_path, decorator.callback_handler()),
],
debug=True)
run_wsgi_app(application)
目前我无法正确设置它。结果,我得到并看到了 HTTP 302 回调响应(虽然它应该被处理程序捕获)而不是我期望的响应。我有两个问题要解决:
- GAE 1.8.0 中的
oauth2client/appengine.py没有callback_path属性,也没有callback_handler()方法,我们是什么应该做的?直接绑定(bind)('/oauth2callback', OAuth2Handler)而不是(decorator.callback_path, decorator.callback_handler())? - 这对
myapp.yaml意味着什么?像这样声明一个新 block 是否正确:- url: /oauth2callback script: oauth2client/appengine.py
Thanks for your help! Here is my current code:
myapp.py
class UpdatePage(webapp2.RequestHandler):
def get(self):
playlist_id = self.youtube_create_playlist()
...
@decorator.oauth_required
def youtube_create_playlist(self):
http = decorator.http()
request = youtube.playlists().insert(...)
response = request.execute(http=http)
return response["id"]
...
update = webapp2.WSGIApplication([
('/update', UpdatePage),
('/oauth2callback', OAuth2Handler)
],
debug=True)
app.yaml
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /
static_files: index.html
upload: index.html
- url: /oauth2callback
script: oauth2client/appengine.py
- url: /update
script: myapp.update
请您参考如下方法:
此库未在 App Engine 中发布。
您应该使用的版本是托管在 project download page 上的 google-api-python-client-1.1 .
我相信您所指的版本是 google-api-python-client 的(有点旧)版本 included in the App Engine SDK .这仅用于为 appcfg.py 执行简单的 OAuth 2.0,并且是执行此简单任务的稳定版本。尽管它在 SDK 中,但它不在运行时中,并且由于这些原因未被认可为 google-api-python-client 的当前版本。
我还想指出,您链接的文章明确指向 installation instructions .
更新:如此处所述,您的 WSGI 处理程序应包含装饰器的回调
routes = [
('/update', UpdatePage),
(decorator.callback_path, decorator.callback_handler()),
]
update = webapp2.WSGIApplication(routes, debug=True)
并且您的 app.yaml 应该允许您的主处理程序应该显式匹配 decorator.callback_path
- url: /oauth2callback
script: myapp.update
或者应该将所有剩余的请求路由到您的 WSGI 处理程序
- url: /.*
script: myapp.update
(第二种方法可能需要向 WSGI 处理程序添加 404 包罗万象。)
