1

我正在尝试将 tornado.auth.TwitterMixin 与回调 url 一起使用,但我遇到了问题。我不确定如何从 Tornado 应用程序中设置回调 url。这是我的 tornado.auth.TwitterMixin 课程:

class TAuthBindingHandler(BaseHandler,tornado.auth.TwitterMixin): 
    @tornado.web.asynchronous 
    def get(self): 
        if self.get_argument("oauth_token", None): 
self.get_authenticated_user(self.async_callback(self._on_auth)) 
            return 
        self.authorize_redirect() 
    def _on_auth(self, user): 
        if not user: 
            raise tornado.web.HTTPError(500, "Twitter auth failed") 
        tuser = self.db.get("SELECT * FROM twitterusers WHERE tid = 
%s",user["id"]) 
        bigU = self.get_current_user() 
        bigU_id = bigU['id'] 
        if not tuser: 
            any_tuser = self.db.get("SELECT * FROM twitterusers LIMIT 
1") 
            if not any_tuser: 
                tuser_id = self.db.execute( 
                    "INSERT INTO twitterusers (name,tid,user_id) 
VALUES (%s,%s,%s)", 
                    user["name"], user["id"], bigU_id) 
            else: 
                self.redirect("/") 
                return 
        else: 
            pass 
        self.redirect(self.get_argument("next", "/"))

我的问题是,我在哪里设置回调网址?我如何在这个类中设置它?

我使用的是 Tornado 1.1,我的 Twitter 应用程序设置中没有设置任何回调。

我正在本地主机上对其进行测试。

此致。

4

1 回答 1

2

嘿,我不确定你是否还需要答案,但self.authorize_redirect需要一个callback_uri. 所以在你的情况下,我会写self.authorize_redirect('http://localhost:8888/authentication-complete'). 我花了一段时间才弄清楚。祝你好运!

于 2011-03-02T16:54:51.593 回答