如果您愿意尝试其他库,可以尝试一下rauth。已经有一个Twitter示例,但是如果您感到懒惰而只想要一个可行的示例,则可以通过以下方法修改该演示脚本:
from rauth import OAuth1Service# Get a real consumer key & secret from https://dev.twitter.com/apps/newtwitter = OAuth1Service( name='twitter', consumer_key='J8MoJG4bQ9gcmGh8H7XhMg', consumer_secret='7WAscbSy65GmiVOvMU5EBYn5z80fhQkcFWSLMJJu4', request_token_url='https://api.twitter.com/oauth/request_token', access_token_url='https://api.twitter.com/oauth/access_token', authorize_url='https://api.twitter.com/oauth/authorize', base_url='https://api.twitter.com/1/')request_token, request_token_secret = twitter.get_request_token()authorize_url = twitter.get_authorize_url(request_token)print 'Visit this URL in your browser: ' + authorize_urlpin = raw_input('Enter PIN from browser: ')session = twitter.get_auth_session(request_token, request_token_secret, method='POST', data={'oauth_verifier': pin})params = {'screen_name': 'github', # User to pull Tweets from 'include_rts': 1, # Include retweets 'count': 10} # 10 tweetsr = session.get('statuses/user_timeline.json', params=params)for i, tweet in enumerate(r.json(), 1): handle = tweet['user']['screen_name'].enpre('utf-8') text = tweet['text'].enpre('utf-8') print '{0}. @{1} - {2}'.format(i, handle, text)
您可以按原样运行,但请确保更新凭据!这些仅用于演示目的。
全面披露,我是rauth的维护者。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)