Understanding the TweepyV2Images Repository
“TweepyV2Images” is a GitHub repository designed to work with the new Twitter API. It uses Python and the Tweepy library, making it accessible for a wide range of users, from beginners to seasoned developers.
https://github.com/jorgez19/TweepyV2Images
Video Tutorial
For a more interactive guide, there’s a YouTube tutorial that comprehensively demonstrates the process from setup to posting images.
You have to install and configure tweepy correct before you can use this helpful script.
import tweepy
# Enter API tokens below
bearer_token = ''
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
# V1 Twitter API Authentication
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
# V2 Twitter API Authentication
client = tweepy.Client(
bearer_token,
consumer_key,
consumer_secret,
access_token,
access_token_secret,
wait_on_rate_limit=True,
)
# Upload image to Twitter. Replace 'filename' with your image filename.
media_id = api.media_upload(filename="your_image.jpg").media_id_string
print(media_id)
# Text to be Tweeted
text = "Hello Twitter!"
# Send Tweet with Text and media ID
client.create_tweet(text=text, media_ids=[media_id])
print("Tweeted!")
I used this script today to post every few hours a new tweet. Please go to the github or yt channel and give them great man a like or comment for his work.