Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to post multiple images using update_with_media #638

Closed
nicholasjon opened this issue Dec 31, 2014 · 8 comments
Closed

Unable to post multiple images using update_with_media #638

nicholasjon opened this issue Dec 31, 2014 · 8 comments

Comments

@nicholasjon
Copy link

I can use update_with_media to post single images without a problem, but whenever I attempt to post multiple images via update_with_media, I get the following error:

Twitter::Error::UnacceptableIO: The IO object for media must respond to to_io

I'm trying to follow the example from: https://github.com/sferik/twitter/blob/master/examples/Update.md

media = %w(/path/to/media1.png /path/to/media2.png).map { |filename| File.new(filename) }
client.update_with_media("I'm tweeting with @gem!", media)

Here's how I'm setting up my client:

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = CONSUMER_KEY
  config.consumer_secret     = CONSUPER_SECRET
  config.access_token        = user.twitter_token
  config.access_token_secret = user.twitter_secret
end

The array of media I have looks like:

media
 => [#<File:/path_to_file/photo/9aN9KzkLQa/9aN9KzkLQa-full.jpg>, #<File:/path_to_file/photo/EUcjNHr5jB/EUcjNHr5jB-full.jpg>]

And here's how I'm trying to make my post:

client.update_with_media("tweet text",media)

Some more info:

The following work:

client.update_with_media("tweet text",media.first) # successful
client.update_with_media("tweet text",media.last) # successful

This does not:

client.update_with_media("tweet text",[media.first])
@Roach
Copy link

Roach commented Jan 18, 2015

You'll need to upload the media first, then reference the media IDs when posting the Tweet:

media_ids = %w(/path/to/media1.png /path/to/media2.png).map do |filename| 
 client.upload File.new filename
end

tweet = client.update "tweet text", {media_ids: media_ids.join(',')}

@tomoyuki28jp
Copy link

@Roach Your comment helps me out, thanks! :)

@jrgillick
Copy link

This works for me with images. Has anyone had success uploading video? When I run this code with an mp4 file:

client.upload(file)

I get this error:

Faraday::TimeoutError: Net::ReadTimeout

@sagarpreet-chadha
Copy link

sagarpreet-chadha commented Jan 23, 2018

@nicholasjon , @jrgillick , @Roach , @tomoyuki28jp , can any of you help me with the following problem .

I was trying to use client.update_with_media("I'm tweeting with @gem!", File.new("/path/to/media.png")) , but could not understand how to make File object for argument .

In short , i want to tweet this image https://pbs.twimg.com/profile_images/793855561456418816/7ysHNRUu.jpg , with message "Hi" , but couldn't figure out the arguments here .

Thank you in advance 😄 !

@andypiper
Copy link

update_with_media was deprecated by Twitter about 3 years ago. You’d be better off following the example @Roach posted above with the two-stage upload and then update method.

@sagarpreet-chadha
Copy link

Thank you @andypiper for your reply !

Still i am not able to upload image , i tried following :

media_ids = %w(https://pbs.twimg.com/profile_images/793855561456418816/7ysHNRUu.jpg).map do |filename| client.upload File.new filename end

and then :
tweet = client.update "tweet text", {media_ids: media_ids.join(',')}

ERROR IS :
screen shot 2018-01-28 at 12 44 52 am

@sagarpreet-chadha
Copy link

sagarpreet-chadha commented Jan 27, 2018

And tried this too :

media_ids = %w(https://pbs.twimg.com/profile_images/793855561456418816/7ysHNRUu.jpg).map do |filename|
require 'open-uri'
open('image.png', 'wb') do |file|
file << open(filename.to_s).read
client.upload File.new file
end
end

and then :

tweet = client.update "tweet text", {media_ids: media_ids.join(',')}

shows ERROR :

screen shot 2018-01-28 at 12 50 05 am

Any help is much appreciated ! Thank you 😄 !

@andypiper
Copy link

You cannot provide a URL as a media ID. You have to upload the image to the media/upload endpoint, and use the ID returned from there.

@sferik sferik closed this as completed Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants