5

What should be the format for the parameter: media , in the call below, for updating with multiple images.

def twitter_status_update_with_media (twitter_client, text, media, opts)
    twitter_client.update_with_media(self.text, media, opts)
end

For a single image, File.new(filepath) works fine..

aelor
  • 10,892
  • 3
  • 32
  • 48
Nikunj Jain
  • 103
  • 1
  • 10

1 Answers1

5

To attach multiple images to a tweet, you first need to upload the images using the upload method:

media_ids = %w(image1.png image2.png image3.png image4.png).map do |filename|
  Thread.new do
    twitter_client.upload(File.new(filename))
  end
end.map(&:value)

This will return media IDs, which you can pass into the media_ids parameter (as a comma-separated string) of the update method.

twitter_client.update("Tweet text", :media_ids => media_ids.join(','))
sferik
  • 1,795
  • 2
  • 15
  • 22
  • how would I apply this code to change the user profile image/avatar? – marriedjane875 Jun 01 '15 at 22:55
  • If media_ids array is empty, the line above will return an error: `Twitter::Error::BadRequest: media_ids parameter is invalid.`. Be careful. – Yaro Aug 01 '16 at 14:34