Mining tweet data via Tweepy

1. 环境配置

  • 1.1 Python环境
    $ python -V
    Python 2.7.13
  • 1.2 Tweepy Install
    $ pip install tweepy
  • 1.3. Twitter account
    配置好Twitter Developer 账号,在Twitter Application页面中 apps.twitter.com/.
    Create new App -- Enter the app you created before -- Keys and access tokens.
    记录如下数据:Consumer Key, Consumer Secret, Access Token, Access Token Secret

2.Get Started !!

# -*- coding: utf-8 -*-
# getStarted
import tweepy
from tweepy import OAuthHandler 
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_Token, access_Token_secret)

# api.home_timeline是一个home的tweet集合(lazy type)
api = tweepy.API(auth)
for tweet in api.home_timeline(): 
    print tweet.text

以上的代码会显示homepage里所有tweets. In my case

Mining tweet data via Tweepy_第1张图片
Screen Shot 2017-04-19 at 7.06.54 pm.png

api.home_timeline()[0].text()就是Donald J.Trump的这条tweet

3.Error exception

  • 3.1 tweepy.error.TweepError: Twitter error response: status code = 429
    http://stackoverflow.com/questions/41786569/twitter-error-code-429-with-tweepy/.

你可能感兴趣的:(Mining tweet data via Tweepy)