TL;DR
v1とv2を両方使い、アップロード、ツイートを行う(らしい)
以下サンプル
import tweepy
# 認証
api_key = ""
api_secret = ""
access_token = ""
access_token_secret = ""
def get_twitter_conn_v1(api_key, api_secret, access_token, access_token_secret) -> tweepy.API:
"""Get twitter conn 1.1"""
auth = tweepy.OAuth1UserHandler(api_key, api_secret)
auth.set_access_token(
access_token,
access_token_secret,
)
return tweepy.API(auth)
def get_twitter_conn_v2(api_key, api_secret, access_token, access_token_secret) -> tweepy.Client:
"""Get twitter conn 2.0"""
client = tweepy.Client(
consumer_key=api_key,
consumer_secret=api_secret,
access_token=access_token,
access_token_secret=access_token_secret,
)
return client
client_v1 = get_twitter_conn_v1(api_key, api_secret, access_token, access_token_secret)
client_v2 = get_twitter_conn_v2(api_key, api_secret, access_token, access_token_secret)
media_path = r"C:~~.mp4"
media = client_v1.media_upload(filename=media_path, media_category="tweet_video")
media_id = media.media_id
client_v2.create_tweet(text="Tweet text", media_ids=[media_id])
こちら必ず指定してあげてください。
media_category="tweet_video"
誰かのお役に立てれば...
参考