Use Koala Ruby gem to post "gif" image

Web Development Web Application rubyonrails Facebook gif

Koala is a famous gem for interacting with Facebook activity. Common interaction can be achieved with single simple method call.

However, when we develop a Facebook feed poster for gif image, the gif image was not automatically played.

Koala common usage

For posting a plain text message to my Facebook feed:

facebook_graph = Koala::Facebook::API.new(facebook_oauth_access_token)
message = "Happy Coding"
facebook_graph.put_connections("me", "feed", message: message)

For posting a picture to my Facebook feed:

facebook_graph = Koala::Facebook::API.new(facebook_oauth_access_token)
message = "Happy Coding"
image_link = "https://image.link"
response = facebook_graph.put_picture(image_link, {:message => message})

Gif gotcha

So, we assumed posting .gif file should be the same. However, if you try to post a gif file using put_picutre, Facebook will freeze your gif and treat it as normal non-animated image.

Solution

It turns out, after try and error, to post a gif image and make it animated, we need to use another method:

facebook_graph = Koala::Facebook::API.new(facebook_oauth_access_token)
message = "Happy Coding"
image_link = "https://image.link"
response = facebook_graph.put_wall_post message, {"link": image_link}

This will make the post being an actual post link and gif will be animated to your Facebook reader: