2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PythonでTweepyを使ってTwitterをごにょごにょする

Last updated at Posted at 2021-05-12

####TwitterDevelopers
https://developer.twitter.com/en/portal/dashboard

###事前設定
初期設定はReadOnlyになっているでツイートするとエラーが発生する。
設定の変更が必要である。
設定を変更したら、各トークンの再発行が必要とのこと!
https://qiita.com/butsuli_shine/items/78fd5ee6fdb4a0581652

#基本系

.py
import tweepy

# 認証に必要なキーとトークン
API_KEY = 'xxxxxxxxxxx'
API_SECRET = 'xxxxxxxxxxxxxx'
ACCESS_TOKEN = 'xxxxxxxxxxxxxxx'
ACCESS_TOKEN_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxx'

# APIの認証
auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

###キーワードに関連するツイートを取得

.py

# キーワードからツイートを取得
api = tweepy.API(auth)
tweets = api.search(q=['くるま'], count=10)

for tweet in tweets:
    print('-----------------')
    print(tweet.text)

###普通にツイート

.py

api = tweepy.API(auth)

#tweet
api.update_status("hello tweepy")

###画像付きでツイート

.py
api = tweepy.API(auth)

#tweet
api.update_with_media(status = "hello tweepy with media", filename = 'hoge.jpg')
2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?