的Using GAE/Decorators導遊告訴我,「你需要一個特定的URL處理程序添加到您的應用程序以處理來自授權服務器重定向回你的應用程序」:如何正確定義GAE的oauth2callback?
def main():
application = webapp.WSGIApplication(
[
('/', MainHandler),
('/about', AboutHandler),
(decorator.callback_path, decorator.callback_handler()),
],
debug=True)
run_wsgi_app(application)
目前我無法正確設置這起來了。因此,我得到並看到HTTP 302回調響應(雖然它應該被處理程序捕獲),而不是我期待的響應。我有兩個問題要解決:
- 的
oauth2client/appengine.py
航運在GAE 1.8.0沒有callback_path
屬性,並沒有callback_handler()
方法,那我們該怎麼辦?直接綁定('/oauth2callback', OAuth2Handler)
而不是(decorator.callback_path, decorator.callback_handler())
? - 這對
myapp.yaml
意味着什麼?是否正確申報新的區塊如下:- url: /oauth2callback script: oauth2client/appengine.py
感謝您的幫助!這裏是我當前的代碼:
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
感謝您指出我的使用權API。但是,安裝後1。1,刷新我的項目,並確保我的導入現在解析爲本地1.1版本,現在我可以使用'(decorator.callback_path,decorator.callback_handler())',但我仍然有同樣的問題:回調isn' t攔截,並且我只是以未處理的302重定向數據而不是我期望的結果結束。 –
您需要在[Google APIs控制檯](http://code.google.com/apis/console)中的項目中定義正確的網址,並且您需要從您的「/ oauth2callback」路徑中取出應用程序。至於'302',這是預期的並且是回調點。 – bossylobster
這是[我的API conf的截圖](https://dl.dropboxusercontent.com/u/368761/bugreport/google-api-cliend-id-configuration.png)。但我不明白你的意思是「302預期和回調點」*。我的理解是'appengine.py'應該攔截它,然後返回原始調用者對我的查詢的答案:在上面的代碼中,我調用'youtube_create_playlist()',但不是獲取新的播放列表ID字符串,而是獲得一個302字符串:[截圖](https://dl.dropboxusercontent.com/u/368761/bugreport/playlist-id-returns-302-string.png)。怎麼了?謝謝! –