[Ruby] Automate Facebook

Using the Ruby Mechanize library, I have been writing a Ruby class to allow automation of parts of Facebook like friending, status updating, and messaging.

You can get the class here and use it like so:

#!/usr/bin/ruby

# Require FacebookBot.rb from the same directory.
require File.join(File.dirname(__FILE__), 'FacebookBot.rb')

# Log in.
fb = FacebookBot.new("example@example.com", "secret")

# Accept all friend requests.
fb.acceptRequests

# Friend a whole page of suggested friends.
fb.suggestedFriends.each { |friendId| fb.requestFriend(friendId) }

# Display all personal messages and recent wall posts.
require "pp"
pp fb.personalMessages
pp fb.recentPosts
This entry was posted in Uncategorized and tagged , , . Permalink.

5 Responses to [Ruby] Automate Facebook

  1. pan says:

    Hi,
    nice script. thanks for that!

    i modified it a bit (just reduced code) but now i have sometimes a problem logging in successfully.
    do you know i FB locks your IP somehow ?

    thanks

    • hac says:

      Hi,
      Just download the class again. Facebook made some changes to the login page a while ago, and I forgot to upload my new Ruby code when I fixed it.

  2. pan says:

    Hi,
    i don’t think, that this is the point. i’m just using the login() Method. And this seems to be successful. but putting the call (“fb = FacebookBot.new(“example@example.com”, “secret”)) in a loop, it seems to be randomly choosen, wether the login is okay or not.

    thanks for uploading the new version. i will check this out!

  3. Tinei says:

    I want to run an information service, for example, someone looking for an apartment to rent or a battery for his car.

    I am currently running the service on MySQL/PHP and using mobile text message for users to access the info. I now want users to be able to do their search from their Facebook chat.

    How do I do this?
    Am not expert programmer, but I am able to quickly understand code and adapt it to my situation

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>