从Twitter获取xauth访问令牌的麻烦

时间:2013-11-25 18:57:27

标签: python python-2.7

我在使用creepymap.py

时遇到问题

我试图让它授权Twitter帐户..但我收到错误消息:

/usr/share/creepy $ python creepymap.py
Traceback (most recent call last):
  File "creepymap.py", line 515, in button_authorize_twitter
    url = self.oauth.get_authorization_url(True)
  File "/usr/lib/python2.7/dist-packages/tweepy/auth.py", line 103, in get_authorization_url
    raise TweepError(e)
tweepy.error.TweepError: HTTP Error 401: Unauthorized

我查看了auth.py,我尝试使用注释代码:

def get_authorization_url(self, signin_with_twitter=False):
        """Get the authorization URL to redirect the user"""
        try:
            # get the request token
            self.request_token = self._get_request_token()

            # build auth request and return as url
            if signin_with_twitter:
                url = self._get_oauth_url('authenticate')
            else:
                url = self._get_oauth_url('authorize')
            request = oauth.OAuthRequest.from_token_and_callback(
                token=self.request_token, http_url=url
            )

后来我读到了这个:

def get_xauth_access_token(self, username, password):
    """
    Get an access token from an username and password combination.
    In order to get this working you need to create an app at
    http://twitter.com/apps, after that send a mail to api@twitter.com
    and request activation of xAuth for it.
    """
    try:
        url = self._get_oauth_url('access_token', secure=True) # must use HTTPS
        request = oauth.OAuthRequest.from_consumer_and_token(
            oauth_consumer=self._consumer,
            http_method='POST', http_url=url,
            parameters = {
                'x_auth_mode': 'client_auth',
                'x_auth_username': username,
                'x_auth_password': password
            }
        )

代码中有什么我应该改变的吗?

P.S抱歉我的英语。这不是我的母语。

谢谢!

编辑: 我只是想通过一些更多的研究来回答我自己的问题。

按照此处的说明获取如何获取xAuth:https://dev.twitter.com/docs/oauth/xauth

0 个答案:

没有答案