指定OAuth1服务的oauth_callback URL(twitter)

时间:2013-05-02 08:26:22

标签: oauth twitter twitter-oauth rauth

我正在尝试使用twitter向我的Web应用程序提供无缝登录。为此,我需要在用户授权我的应用程序后将Twitter重定向到特定的URL。

不希望强制用户复制粘贴PIN以授权该应用。

根据guidelines“使用Twitter实施登录”,在Step 1中,在获取request_token时必须指定oauth_callback。但是使用rauth这样做会引发异常:

Traceback (most recent call last):
  File "/install_dir/web2py/gluon/restricted.py", line 212, in restricted
    exec ccode in environment
  File "/install_dir/web2py/applications/wavilon_portal/controllers/signup.py", line 213, in <module>
  File "/install_dir/web2py/gluon/globals.py", line 194, in <lambda>
    self._caller = lambda f: f()
  File "/install_dir/web2py/applications/wavilon_portal/controllers/signup.py", line 198, in oauth_signup
    authorized, authorize_url = oauth_service.check_authorization()
  File "/python_modules/oauth/service.py", line 230, in check_authorization
    authorize_url = self.get_authorize_url()
  File "/python_modules/oauth/service.py", line 195, in get_authorize_url
    return self.get_authorize_url_oauth1() if self.oauthver == OAUTH1_VER else self.get_authorize_url_oauth2()
  File "/python_modules/oauth/service.py", line 175, in get_authorize_url_oauth1
    request_token, request_token_secret = self.oauth_service.get_request_token(method="POST", oauth_callback=self.redirect_uri)
  File "/virtualenvs/python2.7.2/lib/python2.7/site-packages/rauth/service.py", line 212, in get_request_token
    r = self.get_raw_request_token(method=method, **kwargs)
  File "/virtualenvs/python2.7.2/lib/python2.7/site-packages/rauth/service.py", line 186, in get_raw_request_token
    return session.request(method, self.request_token_url, **kwargs)
  File "/virtualenvs/python2.7.2/lib/python2.7/site-packages/rauth/session.py", line 195, in request
    return super(OAuth1Session, self).request(method, url, **req_kwargs)
TypeError: request() got an unexpected keyword argument 'oauth_callback'

如何为OAuth1设置重定向URI(oauth_callback)?

1 个答案:

答案 0 :(得分:2)

Rauth维护与请求相同的API:twitter.get_request_token(..., params={'oauth_callback': 'http://example.com/callback'})