Ruby, update twitter avatar and background

189 views Asked by At

How can I change/update the avatar and the background image using Ruby?

client = Twitter::REST::Client.new do |config|
    config.consumer_key        = "xxxxx"
    config.consumer_secret     = "xxxxx"
    config.access_token        = "xxxxx"
    config.access_token_secret = "xxxxx"
end

The folder's name is "avis" ...it contains jpg files.

avis = Dir.entries("avis")
avi = avis.sample


puts client.update_profile_image(avi)

My response is:

rb:15:in `on_complete': media type unrecognized. (Twitter::Error::BadRequest)

Even if I put:

path = "/Users/.../avis"

file = File.open(path, "r")

file.each_line { |line| 
  puts line
} 
f.close

My response is:

twitter.rb:819:in `each_line': Is a directory @ io_fillbuf - fd:10 /Users/,,,/Ruby/avis (Errno::EISDIR)
from twitter.rb:819:in `<main>'
1

There are 1 answers

4
phoet On BEST ANSWER

have you followed the api docs? i can't see you encoding anything base64.

The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 400 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.

and what is that 'r' in File.read()? are you mixing that up with File.open()?