Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending multiple medias with tweepy

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 ?

like image 412
Keelah Avatar asked Apr 19 '17 08:04

Keelah


People also ask

How can I get more than 100 tweets on Tweepy?

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).

How many tweets can Tweepy extract?

Tweepy provides the convenient Cursor interface to iterate through different types of objects. Twitter allows a maximum of 3200 tweets for extraction.

Does Tweepy have a limit?

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.

Does Tweepy work with v2?

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).


1 Answers

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)
like image 60
shuuji3 Avatar answered Sep 21 '22 01:09

shuuji3