I am trying to make a Twitter bot with tweepy. It's actually my first twitter BOT, I'm kinda new to it.
I have a list of medias containing the path of each image I need to send. I am able to send tweets with text
api.update_status(status="some text")
Or sending tweets with one single media
api.update_with_media(filename, status="some text with media")
But I need to send many images with my tweet. I heard that I need to upload my files first but I don't know how to integrate them in the tweet. Or maybe there is another way of doing it ?
If you need more than 100 Tweets, you have to use the paginator method and specify the limit i.e. the total number of Tweets that you want. Replace limit=1000 with the maximum number of tweets you want. Replace the limit=1000 with the maximum number of tweets you want (gist).
Tweepy provides the convenient Cursor interface to iterate through different types of objects. Twitter allows a maximum of 3200 tweets for extraction.
The biggest limitation of Tweepy is that of the Twitter API. Twitter's API has various limits depending on your account tier (pricing), and on top of that, Twitter's API limits you to the last 3200 tweets in a timeline.
If you want to retweet a Tweet with Tweepy using the Twitter API v2, you will need to make sure that you have your consumer key and consumer secret, along with your access token and access token secret, that are created with Read and Write permissions (similar to the previous example).
In case you want to upload multiple images, you can use Twitter API's media/upload
via Tweepy's api.media_upload()
method.
This method returns a response object containing media_id
and you can attach multiple media_ids
to api.update_status()
.
So the code you may want to write is like this:
# Upload images and get media_ids
filenames = ['1.png', '2.png', ...]
media_ids = []
for filename in filenames:
res = api.media_upload(filename)
media_ids.append(res.media_id)
# Tweet with multiple images
api.update_status(status='many images!✨', media_ids=media_ids)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With