Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading multiple images on twitter using Ruby on Rails Twitter Gem

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

like image 256
Nikunj Jain Avatar asked Oct 07 '14 08:10

Nikunj Jain


1 Answers

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(','))
like image 157
sferik Avatar answered Oct 18 '22 13:10

sferik