Skip to content

Instantly share code, notes, and snippets.

@JorenSix
Created May 9, 2019 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JorenSix/37ef68021b41c87ac6338cf0c57f7843 to your computer and use it in GitHub Desktop.
Save JorenSix/37ef68021b41c87ac6338cf0c57f7843 to your computer and use it in GitHub Desktop.
Automatically post status update to facebook page
require 'mechanize'
def facebook_page_status_update(email,password,page_name,message)
agent = Mechanize.new
agent.user_agent_alias = 'Android'
#go to the login page
login_page = agent.get('https://m.facebook.com/')
#get the login form
login_form = agent.page.form_with(:method => 'POST')
login_form.email = email
login_form.pass = password
agent.submit(login_form)
#using the logged in agent, go to the page's page
message_page = agent.get("https://m.facebook.com/#{page_name}/")
#get the form to submit a message
message_form = agent.page.form_with(:method => 'POST')
if message_form.nil?
raise "Unable to login: check email/password and page name"
else
#print info on the form
#pp message_form
#the first textarea expects the content use \n for a newline
message_form.textareas.first.value = message
#print information about the form
#pp message_form
#Submit the form using the first button
agent.submit(message_form, message_form.buttons.first)
end
end
facebook_page_status_update("your@email.com","fb_password","fb_page","My message \n continued")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment