LoginSignup
6
6

More than 5 years have passed since last update.

python3でtwitter

Last updated at Posted at 2014-01-03

twitterからツイートを取得するため、twitterライブラリを使った
https://github.com/sixohsix/twitter

アプリを登録

登録後、Consumer keyとConsumer secretを確認する

OAUTH_TOKEN、OAUTH_SECRETの取得

twitterライブラリにoauth_dance関数が用意されているので、それを呼び出し。
呼び出し後ブラウザでアプリ認証画面が開くので、ログインすればPIDが表示される。
PIDをコンソールに入力しEnter。
Oauth_TokenとOauth_secretが出力される。

oauth_test.py
from twitter import *
#第1匹数は何でもよい。
#第4匹数にファイル名を指定すれば、そのファイルに保存される模様
print(oauth_dance('hoge',consumer_key, consumer_secret))

タイムラインの読み込み

※ライブラリのサンプルそのまま

get_timeline
from twitter import *

# 上記で取得した各token,secretを設定しアクセス
t = Twitter(
            auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
                       CONSUMER_KEY, CONSUMER_SECRET)
           )
t.statuses.home_timeline()
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6