sportivivi
sportivivi

Reputation: 11

upload several images in a post to twitter with tweepy library

to update with a image there is no problem. This is the code and it wotks:

import tweepy
from subprocess import call
from datetime import datetime
import time

...key and tokens...

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)
photo_path = '/directory/image.jpg'
status = 'Subject o text'
api.update_with_media(photo_path, status=status)

but what if i want post a tweet with multiple images? it is posible to do that with this library?

Upvotes: 1

Views: 939

Answers (1)

Vlad B.
Vlad B.

Reputation: 11

Because update_with_media endpoint is deprecated by Twitter, you should use media_upload like this:

api = tweepy.API(auth)
images = ('image1.png', 'image2.png')
media_ids = [api.media_upload(i).media_id_string  for i in images] 
status = 'Subject o text'
api.update_with_media(media_ids=media_ids, status=status)

Upvotes: 1

Related Questions