'Twython'에 해당되는 글 1건

  1. 2016.04.25 Twython 설치 및 예제 1

1) twython 이란?

- 파이썬에서 트위터 데이터를 가져올 때 필요한 Twitter API

  

2) twython 설치 명령어

pip install twython


3) twython API 사용을 위한 OAuth 인증받기

-사이트 주소: http://dev.twitter.com/apps/

-필요한 정보: Consumer Key, Consumer Secret, Access Token, Access Token Secret 


4) 예제 코드

>>> from twython import Twython

>>> APP_KEY='Consumer Key' 

>>> APP_SECRET='Consumer Secret'

>>> OAUTH_TOKEN='Access Token'

>>> OAUTH_TOKEN_SECRET='Access Tocken Secret'

>>> twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

>>> tweets = twitter.search(q='네모난', count=1)

>>> from pprint import pprint

>>> pprint(tweets)


5) 출력: '네모난'이라는 단어가 들어가 있는 트윗 데이터 1개


6) 추가 예제: 글 내용만 출력하기

>>> text=tweets['statuses']

>>> text[0]['text']



#참고 사이트: 

1) http://stackoverflow.com/questions/19095257/using-twython-to-send-a-tweet-twitter-api-error/19196583#19196583


2) https://www.lucypark.kr/courses/2015-dm/text-mining.html


3) https://twython.readthedocs.org/en/latest/usage/starting_out.html




Posted by miniature88
,