Twitter OAuth APIを使ったアプリケーションを作っています。
(Ruby:2.3.6,Rails: 5.1.4,‘omniauth-twitter’ gem,Amazon Linux AMI)
その中で、写真つきツイートをしようとすると
client.update_with_media( comment, image_path )
ときどきエラーが起きます。以下エラー文です。
[DEPRECATED] :mime_type option deprecated, use :content_type
Twitter::Error::Unauthorized (Invalid or expired token.):
Completed 500 Internal Server Error
それから、理由を色々探してみて、画像が10kbより小さい場合(画像パスが文字列としてTwitterに認識される)らしいので、モンキーパッチを追加しました。
module Twitter::Image def self.open_from_url(image_path) image_file = open(image_path) return image_file unless image_file.is_a?(StringIO) file_name = File.basename(image_path) temp_file = Tempfile.new(file_name) temp_file.binmode temp_file.write(image_file.read) temp_file.close open(temp_file.path) end end image_path = Twitter::Image.open_from_url(image_path) client.update_with_media( comment + "\nhhbox.net/#{user.screen_name}", image_path )
しかしながら、解決にはいたらず、まだエラーが時々でます。
どなたかお詳しい方。助けていただけないでしょうか?
よろしくお願いします。
あなたの回答
tips
プレビュー