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()
方法,我们应该怎么做?直接绑定('/oauth2callback', OAuth2Handler)
而不是(decorator.callback_path, decorator.callback_handler())
吗?这对
myapp.yaml
意味着什么?声明一个新的块是否正确:- 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捕获所有功能。)