Skip to content

Instantly share code, notes, and snippets.

@mojowen
Created October 11, 2016 21:33
Show Gist options
  • Select an option

  • Save mojowen/063bf9c0e80d20a645c1ce4dbc035229 to your computer and use it in GitHub Desktop.

Select an option

Save mojowen/063bf9c0e80d20a645c1ce4dbc035229 to your computer and use it in GitHub Desktop.
The Facebook Sharer will not show a share image if the image is kind of large - this ruby function requests to share a URL programmatically so when a real users attempts to share the image will appear.
require 'rest-client'
def clear_url(url)
cookie = "" # Load facebook and copy and paste your session detail in here
cookie = Hash[ cookie.split('; ').map { |line| line.split('=') } ]
resp = RestClient.get "https://www.facebook.com/sharer/sharer.php?u=#{url}", { cookies: cookie }
raise 'whoops' if resp.code != 200
sleep 5 # Not sure how fast we can go - no complaints at one request per 5 seconds
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment