Very simple, I want to upload a .mp4 to X using python. Currently I’m using Tweepy but for me it will not matter whether the solution uses Tweepy or not.
The following code is what i’m working with, I can post a text-only tweet and a tweet with picture and text but i can’t get the video to work.
import os
import tweepy
from dotenv import load_dotenv
load_dotenv()
X_BEARER_TOKEN = os.getenv('X_BEARER_TOKEN')
X_API_KEY = os.getenv('X_API_KEY')
X_API_SECRET = os.getenv('X_API_SECRET')
X_ACCESS_TOKEN = os.getenv('X_ACCESS_TOKEN')
X_ACCESS_TOKEN_SECRET = os.getenv('X_ACCESS_TOKEN_SECRET')
X_CLIENT_ID = os.getenv('X_CLIENT_ID')
X_CLIENT_SECRET = os.getenv('X_CLIENT_SECRET')
x_client = tweepy.Client(
bearer_token=X_BEARER_TOKEN,
consumer_key=X_API_KEY,
consumer_secret=X_API_SECRET,
access_token=X_ACCESS_TOKEN,
access_token_secret=X_ACCESS_TOKEN_SECRET
)
auth = tweepy.OAuthHandler(X_API_KEY, X_API_SECRET)
auth.set_access_token(X_ACCESS_TOKEN, X_ACCESS_TOKEN_SECRET)
x_api = tweepy.API(auth)
media_video = x_api.media_upload('output/1dty38f.mp4', chunked=True, media_category="tweet_video")
media_photo = x_api.media_upload('output/terry.png')
print(f'Video - {media_video}n')
print(f'Photo - {media_photo}n')
tweet = x_client.create_tweet(text='Hello', media_ids=[media_video.media_id_string])
This is the print result that indicates the video file is ‘Invalid or Unsupported media.’ which i really don’t understand why.
print result
I’ve tried to use the API.update_status from tweepy.API but it gives me a whole new error.
error using API.update_status
Simão Teles Arrais is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.