Saturday, 15 September 2012

ruby - Twitter rails gem Update_with_media returns Unauthorized -



ruby - Twitter rails gem Update_with_media returns Unauthorized -

i'm using twitter gem authenticate , share content twitter. need include image i'm using "update_with_media" method, so:

def tweet client = twitter::rest::client.new |config| config.consumer_key = "my consumer key" config.consumer_secret = "my consumer secret" config.access_token = "my access token" config.access_token_secret = "my secret access token" end url = @flip.image_urls[:normal].to_s r = open(url) bytes = r.read img = magick::image.from_blob(bytes).first fmt = img.format info = stringio.new(bytes) data.class.class_eval { attr_accessor :original_filename, :content_type } data.original_filename = @flip.slug + "." + fmt unless @flip.slug.nil? data.content_type='image.jpg' client.update_with_media(personal_message, data) end

and response:

twitter::error::unauthorized (could not authenticate you):

for every other interaction twitter, followers, or tweet (update without media) works fine same account, credentials correct.

any thoughts? bug on twitter's api or twitter gem?

i apreciate help, thanks.

i figured out problem. error given twitter misleading , not accurate.

the problem code can't utilize update_with_media method using stringio file, has file object (file class).

so solution:

client.update_with_media(message_link, open(url))

where url image url wherever need. in case image url flip model stored on aws.

ruby-on-rails ruby twitter ruby-on-rails-4 twitter-gem

No comments:

Post a Comment