Hi I've been trying to add four images to a tweet using the twitterAPI module in python - This code below unfortunately only renders one of the images from data in the tweet. Can someone point me in the right direction to attach four images to the tweet? My code is below (minus the imports, and secret keys)
api = TwitterAPI(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET)
output_message = "Four Cool Images:"
data = ""
for x in range(0, 4):`enter code here`
filename = "/temp/images/image" + x + ".jpg" # file name of image.
file = open(filename, 'rb')
stream = file.read()
data = data + stream
r = api.request('statuses/update_with_media', {'status':output_message}, {'media[]':data})
print(r.status_code)
'statuses/update_with_media' is deprecated. Below is the preferred method.
from TwitterAPI import TwitterAPI
TWEET_TEXT = 'some tweet text'
IMAGE_PATH = './some_image.png'
api = TwitterAPI(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_TOKEN_KEY,ACCESS_TOKEN_SECRET)
# STEP 1 - upload image
file = open(IMAGE_PATH, 'rb')
data = file.read()
r = api.request('media/upload', None, {'media': data})
print('UPLOAD MEDIA SUCCESS' if r.status_code == 200 else 'UPLOAD MEDIA FAILURE')
# STEP 2 - post tweet with a reference to uploaded image
if r.status_code == 200:
media_id = r.json()['media_id']
r = api.request('statuses/update', {'status':TWEET_TEXT, 'media_ids':media_id})
print('UPDATE STATUS SUCCESS' if r.status_code == 200 else 'UPDATE STATUS FAILURE')