使用tornado.auth.TwitterMixin 和回调URL?
我正在尝试将tornado.auth.TwitterMixin 与回调url 一起使用,但是 我遇到了问题。 我不知道如何在 Tornado 中设置回调 url 应用。 这是我的 torchado.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", "/"))
我的问题是,我在哪里设置回调 url?我该如何设置它 这堂课?
我正在使用 Tornado 1.1,并且我的 Twitter 应用程序设置中没有设置任何回调。
我正在本地主机上测试它。
此致。
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.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", "/"))
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,我不确定您是否仍然需要答案,但是
self.authorize_redirect
需要一个callback_uri
。因此,在您的情况下,我会编写 self.authorize_redirect('http://localhost:8888/authentication-complete') 。我花了一段时间才弄清楚。祝你好运!Hey, I'm not sure if you still need the answer, but
self.authorize_redirect
takes acallback_uri
. So in your case, I would writeself.authorize_redirect('http://localhost:8888/authentication-complete')
. It took me a while to figure it out. Good luck!