Tweety“未获取Access_token数据”

时间:2011-10-18 15:11:23

标签: python twitter twitter-oauth tweepy

无法获取oauth访问令牌和从请求令牌交换的秘密任何帮助都会很棒其他一切似乎都在正确的地方

 TweepError: HTTP Error 401: Unauthorized


callback_url = urllib.quote("%s?twitterCallback=1" % self.request.url)

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)#, callback_url

try:
    redirect_url = auth.get_authorization_url()
except tweepy.TweepError:
    print 'Error! Failed to get request token.'

request_token = [auth.request_token.key, auth.request_token.secret]

tmpldict['twitauthurl'] = redirect_url

oauth_verifier = self.request.values.get('oauth_verifier',None)
oauth_token = self.request.values.get('oauth_token',None)

if oauth_verifier:
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

    auth.set_request_token(request_token[0], request_token[1])

    access_token = {}
    try:
            access_token = auth.get_access_token(oauth_verifier)

    except tweepy.TweepError:
            print 'Error! Failed to get access token.'

1 个答案:

答案 0 :(得分:0)

需要将请求令牌数据存储在会话中并在第二部分中调用它。该调用正在创建一个新的请求令牌。