I used the twitter library to get tweets from twitter https://github.com/sixohsix/twitter
https://dev.twitter.com/apps
After registration, check the Consumer key and Consumer secret
The oauth_dance function is provided in the twitter library, so call it. After calling, the app authentication screen opens in the browser, so if you log in, the PID will be displayed. Enter the PID into the console and press Enter. Oauth_Token and Oauth_secret are output.
oauth_test.py
from twitter import *
#The first number may be anything.
#If you specify a file name for the 4th animal, it will be saved in that file
print(oauth_dance('hoge',consumer_key, consumer_secret))
get_timeline
from twitter import *
#Each token obtained above,Set secret and access
t = Twitter(
auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
CONSUMER_KEY, CONSUMER_SECRET)
)
t.statuses.home_timeline()
Recommended Posts