Tweepy 설치하기

1
pip install tweepy

또는

1
2
git clone https://github.com/tweepy/tweepy.git
python setup.py install


Tweepy 예제 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import tweepy
 
API_KEY = '~~~'
API_SECRET = '~~~'
ACCESS_KEY = '~~~'
ACCESS_SECRET = '~~~'
 
oAuth = tweepy.OAuthHandler(API_KEY, API_SECRET)
oAuth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth_handler = oAuth, api_root = '/1.1')
 
if __name__ == "__main__":
    userID = 123456789
    user = api.get_user(userID)
    timeline = api.user_timeline(userID)
 
    # PRINT USER'S TIMELINE TWEETS
    for tweet in timeline:
        try:
            texts = tweet.text
            print(texts)
        except AttributeError as e:
            print(e)
 
    # PRINT USER'S FRIENDS IDs
    for friend in user.friends(count = 200):
        print(friend.id)


Reference