Help ! ruby gem Twitter , and want to upload_with_media , but got a error message : "Could not authenticate with OAuth"

caicai89
@caicai89 snow

I am using ruby gem Twitter , I want to upload image ,but this gem don't have this method .
so I add a method named upload_with_medio which is like update_profile_image

  1.       def update_with_media(status,media, options={})
  2.         response = post('https://upload.twitter.com/1/statuses/update_with_media', options.merge(:status => status,"media[]" => media))
  3.         format.to_s.downcase == 'xml' ? response['user'] : response
  4.       end

I can upload profile image but when I call method update_with_media I got a error message :
"POST https://upload.twitter.com/1/statuses/update_with_media.json: 401: Could not authenticate with OAuth. (Twitter::Unauthorized)"

Thanks~~

50 weeks 18 hours ago

Replies

episod
@episod Taylor Singletary

You'll need to make sure that you're explicitly setting the content-types for the request in a way that that both the underlying OAuth gem/library will understand it as well as the library's HTTP connection logic. I'm not familiar with the abstraction layer this library has, but that post() method likely has a way to pass in HTTP headers.

You also might need to look closer at the library to make sure that setting an explicit path with host and protocol on that connection proxy is possible. Many libraries establish a base host that you may need to override in order to repoint it at upload.twitter.com.

50 weeks 13 hours ago