Python tweet multiple images Twitter API
<p>I'm trying to write a script that will post two images to Twitter using the API, any idea why this doesn't work? It only posts the first image. New to this, thanks!   </p>

<pre><code>from TwitterAPI import TwitterAPI
import urllib

api = TwitterAPI('','','','')

x = []

file = open('im1.png', 'rb')
data = file.read()
r = api.request('media/upload', None, {'media': data})
media_id = r.json()['media_id']
print('UPLOAD MEDIA SUCCESS' if r.status_code == 200 else 'UPLOAD MEDIA FAILURE')
x.append(str(media_id))


file = open('im2.png', 'rb')
data1 = file.read()
r = api.request('media/upload', None, {'media': data1})
media_id = r.json()['media_id']
print('UPLOAD MEDIA SUCCESS' if r.status_code == 200 else 'UPLOAD MEDIA FAILURE')
x.append(str(media_id))


if r.status_code == 200:
    media_id = r.json()['media_id']
    r = api.request('statuses/update', {'status':'Test', 'media_ids':media_id})
    print('UPDATE STATUS SUCCESS' if r.status_code == 200 else 'UPDATE STATUS FAILURE')
</code></pre>

<p>You are almost there. You just forgot to use your array of ids <code>x</code>. Make the following change to the last part of your code.</p>

<pre><code>if r.status_code == 200:
    media_id = ','.join(x)
    r = api.request('statuses/update', {'status':'Test', 'media_ids':media_id})
    print('UPDATE STATUS SUCCESS' if r.status_code == 200 else 'UPDATE STATUS FAILURE')
</code></pre>

python twitter