开发者

Using tornado.auth.TwitterMixin with a callback URL?

I am trying to use tornado.auth.TwitterMixin with a callback url, but I am having problems with it. I am not sure how do i set the callback url from within the Tornado Application. Here's my class for tornado.auth.开发者_StackOverflowTwitterMixin :

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", "/"))

My question is, where do i set the callback url ? How do i set it in this class?

I'm using Tornado 1.1 and I do not have any callbacks set in my twitter app settings.

I'm testing it out on localhost.

Best Regards.


Hey, I'm not sure if you still need the answer, but self.authorize_redirect takes a callback_uri. So in your case, I would write self.authorize_redirect('http://localhost:8888/authentication-complete'). It took me a while to figure it out. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜