1
0

More than 3 years have passed since last update.

tweepyを使った認証~ユーザー認証とアプリ認証(Python)

Last updated at Posted at 2020-02-07
auth.py
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""

とした時に、

ユーザー認証(user auth)

auth.py
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

アプリ認証(app auth)

auth.py
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth)

となります。ユーザー認証とアプリ認証はレート制限が全く違います!
https://developer.twitter.com/en/docs/basics/rate-limits
bandicam 2020-02-08 06-15-52-799.jpg

また、api = の形になっていますが、これはtweepyにおいてのAPIオブジェクトとなっており、
http://docs.tweepy.org/en/latest/api.html
bandicam 2020-02-08 06-18-13-870.jpg
print(api.rate_limit_status())
のようにすれば、
bandicam 2020-02-08 06-19-23-455.jpg
こんな感じ(JSON)で残りリクエスト数が返ってきます。
そして、ツイートが検索したいという時は、
bandicam 2020-02-08 06-20-19-954.jpg
このようにリファレンスを開くといろいろ分かると思います。

ありがとうございました。

定型文
ツイッター(@kenkensz9)にいつもいるので何かあればどうぞ
よろしければいいねお願いします!

1
0
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
1
0