Passing a Tempfile to update_with_media causes Exception #306

brightchimp opened this Issue Aug 15, 2012 · 2 comments

3 participants



I am using ruby 1.8.7, and moving from gem version 2.1.0 to 3.5.0 (I know, a big jump).
EDIT: And moving from faraday 0.7.6 to 0.8.1 (looks likely relevant from digging around).

Posting a tweet with a photo in version 2.1.0 accepts a Tempfile object (remote file opens with open-uri).
Trying to do the same in 3.5.0 fails to post the tweet and raises:
Twitter::Error::Unauthorized: Could not authenticate with OAuth

Steps to reproduce are below.
The local_file object is of class File. The remote_file object is of class Tempfile.
The final update_with_media succeeds in 2.1.0, but fails in 3.5.0:

your_twitter_consumer_key = 'SETTHIS'
your_twitter_consumer_secret = 'SETTHIS'
your_user_token = 'SETTHIS'
your_user_secret = 'SETTHIS'

remote_image_path = ''
require 'open-uri'
local_image = open(local_image_path)
remote_image = open(remote_image_path)

Twitter.configure do |config|
config.consumer_key = your_twitter_consumer_key
config.consumer_secret = your_twitter_consumer_secret
config.oauth_token = your_user_token
config.oauth_token_secret = your_user_secret

client =
res = client.update_with_media("#{} Tweet with a local photo", local_image, {})
res = client.update_with_media("#{} Tweet with a remote photo", remote_image, {})

@sferik sferik closed this in f29b24d Aug 26, 2012

I am facing the same issue, using version 4.7.0. Can you please suggest what could be the issue?

What i understand from the sourcecode of 4.x version is, the post method doesn't send any signature_parameters if there is any param responding to "to_io" method. Which means, if any file in there, it wont add signature params... and this could be the reason its not able to authenticate.

Please suggest what shall we do, Other than updating to latest version. I am already trying to test this with latest version.


Updated the Gem to 5.5.1, now its able to post the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment