Created
May 9, 2019 06:52
-
-
Save JorenSix/37ef68021b41c87ac6338cf0c57f7843 to your computer and use it in GitHub Desktop.
Automatically post status update to facebook page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("[email protected]","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