我使用DjTweepy模型一起运行tweepy + django,一切顺利,直到我尝试回调函数:
def callback(request):
verifier = request.GET.get('oauth_verifier')
oauth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
token = request.session.get('unauthed_token_tw', None)
# remove the request token now we don't need it
request.session.delete('unauthed_token_tw')
oauth.set_request_token(token[0], token[1])
# get the access token and store
try:
oauth.get_access_token(verifier)
except tweepy.TweepError:
print ('Error, failed to get access token!!!!')
request.session['access_key_tw'] = oauth.access_token.key
request.session['access_secret_tw'] = oauth.access_token.secret
response = HttpResponseRedirect(reverse('info'))
return response
我相信声明: oauth.set_request_token(令牌[0],令牌[1])来自旧版本的Tweepy:http://sourcecodebrowser.com/jsonbot/0.80.3/classjsb_1_1contrib_1_1tweepy_1_1auth_1_1_o_auth_handler.html#adcac2093309df3a93dd95f9c2c3c91a9
我不确定它现在是否有用,保持结果(当然): 的' OAuthHandler'对象没有属性' set_request_token' 删除它会导致: 的' NoneType'对象没有属性'键'
该怎么办? 感谢
答案 0 :(得分:2)
这里的文档也有点令人困惑。我已经使用了tweepy 3.3.0,它的工作原理如下。
oauth = tweepy.OAuthHandler(consumer_token, consumer_secret)
oauth.request_token = {'oauth_token': request.args.get('oauth_token') ,'oauth_token_secret': request.args.get('oauth_verifier') }
get_token = oauth.get_access_token(request.args.get('oauth_verifier'))
api = tweepy.API(oauth)
#api.update_status('tweepy + oauth!here Is sparta')
public_tweets = api.home_timeline()
此处 token = session.get(' request_token')只不过是' oauth_token' 和
auth.request_token = token 此处需要设置字典 {' oauth_token&#39 ;: request.args.get(' oauth_token'),&#39 ; oauth_token_secret&#39 ;: request.args.get(' oauth_verifier')}
它工作正常!。