Tweepy 설치하기

pip install tweepy

또는

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


Tweepy 예제 코드

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