简体   繁体   English

OAuth Twitter龙卷风python

[英]OAuth twitter tornado python

I'm trying to integrate a twitter login on my app, I wrote this code 我正在尝试在我的应用程序中集成Twitter登录,我编写了此代码

class AuthTwitterHandler(tornado.web.RequestHandler, tornado.auth.TwitterMixin):
    @tornado.web.asynchronous
    def get(self):
        print 'GET'
        if self.get_argument("oauth_token", None):
            print 'GET OK'
            self.get_authenticated_user(self.async_callback(self._on_auth))
            return
        print 'REDIRECT'
        self.authenticate_redirect()

    @tornado.web.asynchronous
    def _on_auth(self, user):
        print 'ONAUTH'
        if not user:
            print 'Broken'
            raise tornado.web.HTTPError(500, "Twitter auth failed")
            # Save the user using, e.g., set_secure_cookie()
        print 'not Broken'
        self.set_secure_cookie("user", tornado.escape.json_encode(user))

and as callback_url in my twitter app I put the same address of this handler, my output is: 在我的Twitter应用程序中,将callback_url作为该处理程序的相同地址,我的输出是:

GET
REDIRECT
GET
GET OK
ONAUTH
Broken

and my log said: 我的日志说:

2012-06-18 16:56:09,650 - root - INFO - Logging started
2012-06-18 16:56:09,821 - root - INFO - Server starting on port 443
2012-06-18 16:56:16,170 - root - INFO - 304 GET /auth (127.0.0.1) 0.72ms
2012-06-18 16:56:19,215 - root - INFO - 302 POST /auth (127.0.0.1) 1.35ms
2012-06-18 16:56:19,719 - root - INFO - 302 GET /auth/twitter (127.0.0.1) 429.17ms
2012-06-18 16:56:20,464 - root - WARNING - Missing OAuth request token cookie
2012-06-18 16:56:20,465 - root - WARNING - 500 GET /auth/twitter?oauth_token=Nbed9YQseoNC3YjdFkbOPS5An7OhfewcEgp3oPuq4&oauth_verifier=uGWWoItQ7SXa1Bt8lSDs1N8iVXvBFIcKtCEpZ1mmI4 (127.0.0.1): Twitter auth failed
2012-06-18 16:56:20,465 - root - ERROR - 500 GET /auth/twitter?oauth_token=Nbed9YQseoNC3YjdFkbOPS5An7OhfewcEgp3oPuq4&oauth_verifier=uGWWoItQ7SXa1Bt8lSDs1N8iVXvBFIcKtCEpZ1mmI4 (127.0.0.1) 12.96ms

can anyone help me? 谁能帮我?

This may be a dupe of " Missing OAuth request token cookie error using tornado and TwitterMixin ", so three questions: 这可能是“ 使用龙卷风和TwitterMixin缺少OAuth请求令牌cookie错误 ”的重复,因此出现三个问题:

  1. What is the fully qualified domain name of your website? 您的网站的完全限定域名是什么?
  2. If you use a web browser plugin like HTTPFox, or use Wireshark, what is the exact cookie that you get back? 如果您使用HTTPFox之类的Web浏览器插件,或使用Wireshark,您得到的确切的cookie是什么? More precisely what domain is the cookie associated with? 更确切地说,cookie与哪个域关联?
  3. What is the full URL of your Twitter app's callback URL? Twitter应用程序的回调URL的完整URL是什么?

This isn't an error with Tornado; 这不是龙卷风的错误。 I've used the exact same code with success. 我成功使用了完全相同的代码 So it's worth focusing on your Twitter app's settings, where your site is hosted, and the exact cookie you're getting back. 因此,值得关注您的Twitter应用程序的设置,托管网站的位置以及您返回的确切cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM