Topic: Interacting with Facebook using Ruby

Hello guys. I have been lurking in the forums for a while. This is the first time I have needed help that I could not find by googling. I have been tasked with using a ruby script. The basic idea is to have a method called 'setFacebookStatus'.

This method will look like the following:

def setFacebookStatus(username, password, status_text)
    #log into facebook using the supplied details
    #if the user logs in properly
        #update the logged in users status
        #log out of the user's account
        #raise an error

I have noticed that if I was logged in, I could do a post request to:

with the parameters:

['status' => @status_message,  'post_form_id' => @post_form_id]

I have even found a perl script that does something similar: …

I am familiar with ruby as a language and have been using rails for a while now. However, this is the first I have come across having to do something like this.

If anyone could help me with writing this code or at least point me in the right direction, I would really appreciate it.

Re: Interacting with Facebook using Ruby

I think ScRUBYt would be a good starting point. While its more an scaper than an automator, browsing the source of methods like "click_link" or "fill_form" would give you a feel of the best way to go about it.


Re: Interacting with Facebook using Ruby

Thanks. That is definitely a good resource. I know it is a lot to ask but I was wondering if you or someone else would be willing to help me port over this code I write in perl a while ago.

This is code I wrote for another job a year or so ago that takes an email, password and uses it to log into facebook with a script. It uses the Mechanize function to do it. Could someone who has a better handle on this in ruby help me port this code over? It would be a great start.

use strict;

my $email = $ARGV[0];
my $password = $ARGV[1];

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();

my $url = "";

    $mech->get( $url );

    $mech->follow_link(text => "login");

    my $i;
    my $j;

    $i = $mech->form_with_fields(("email","pass"));
    my $response = $mech->submit_form(
        with_fields  => {
            email => $email,
            pass => $password,