TwitterDM

PHOTO EMBED

Mon Sep 05 2022 05:14:55 GMT+0000 (Coordinated Universal Time)

Saved by @kokohachi #python

# ライブラリの読み込み
import tweepy

#****には自身のコードを入力してください
CONSUMER_KEY = '****'
CONSUMER_SECRET = '****'
ACCESS_TOKEN = '****'
ACCESS_SECRET = '****'

#twitter認証
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)

# アカウント指定(Twitterアカウントの@以降の英数字)
Account = '****'

# アカウントの内部IDを取得する
inner_id = api.user_timeline(Account, count=1, page=0)[0].user.id

api.send_direct_message(recipient_id=inner_id,text='Hello world!')
content_copyCOPY

TwitterでDM送信

https://python-man.club/python_twitter_tweepy/