5

So I'm trying to program a simple desktop application to login into someone's facebook. Right now that's my only objective, just log into facebook. I'm coding in Ruby and am using shoes GUI toolkit. Here's the code I have so far:

Shoes.app do
  stack(:margin => 12) do
    para "Enter your login information"
    flow do
      para "Username: "
      @login_text = edit_line
    end
    flow do
      para "Password: "
      @pass_text = edit_line(:secret => true)
    end

    @login_button = button "Login"
    @login_button.click {
      login(@login_text.text, @pass_text.text )
    }
  end
end

def login(username, password)
  alert(username + "   " + password)
end

So it's definitely getting to the login function because it alerts whatever I type into the textbox after clicking the login button. But I have no idea where to start as far as the logging into the facebook portion goes... I've tried look at Facebook's instructions and I've also tried google searching on the subject but all the tutorials are for rails.

I've seen mechanize but I don't know how well that will play with shoes because it looks like it's trying to implement it's own buttons and stuff.

I'm super new to ruby and have no idea how to login from a desktop app. Any advice or tutorials to help me out? I mean I need to start from "first include these files...", I'm an absolute beginner.

Community
  • 1
  • 1
Richard
  • 5,840
  • 36
  • 123
  • 208
  • 1
    What do you need to do once you log into Facebook? – Linuxios Apr 27 '13 at 17:11
  • @Linuxios well my program is going to display a list of information on the screen, essential if you like one thing on the list then you can 'like' it and it will get posted on your wall – Richard Apr 27 '13 at 17:55
  • 3
    Generally, you don't login to Facebook by storing user name and password to FB at your end. The process is designed around trusting (or not) your apps application tokens. Essentially you will need to provide an embedded browser in your app, capable of interacting with FB, and the combination of your app id, plus user interaction on that browser, will grant your app a security token with access to fetch parts of the FB graph data that the user has agreed you can have. – Neil Slater Apr 28 '13 at 09:46
  • @NeilSlater okay, any ideas on how to embed a web browser into a ruby application? – Richard Apr 28 '13 at 14:38
  • @Richard: Other than that it is *probably* possible, sorry no. I have integrated FB before, but it was for a web site (and server side in Perl). – Neil Slater Apr 28 '13 at 16:47
  • @NeilSlater well logging into *anything* would be nice, because I can just change it to twitter. Any ideas on how to do login for desktop application for *any* web service? – Richard Apr 28 '13 at 17:20
  • 1
    That varies a lot by service, and specifically by how that service does authentication - there are several common approaches. Services that use OAuth will usually require a browser. For others, you may simply need to do an https POST request with the username and password, using a client like the `httparty` gem, or the `rest-client` gem. Yet others might use basic auth (which you can usually access via the same http client gems). – Neil Slater Apr 28 '13 at 19:01
  • @NeilSlater I think httparty is a step in the right direction...I'll try it out...but any ideas on how to setup the code to attempt a login to twitter? Thanks for all your help – Richard Apr 28 '13 at 21:55
  • The most used standard is OAuth but if you want to use it you need a web server because the authentication flow require a **callback_url**. With Oauth you can use the same protocol to authenticate your app in almost all Social Network. An other solution is to create a web page that use the JS SDK provided by Facebook and then read cookies. [Here](https://developers.facebook.com/docs/concepts/login/login-architecture/) you can see all the different authentication flow provided by FB. Once you get an access token, you can use [Koala gem](https://github.com/arsduo/koala) to play with Graph API. – marquez Apr 30 '13 at 09:03

1 Answers1

4

As mentioned in the comments, your best bet might be to use OAuth, but you don't necessarily need to implement anything else to get it working. Using the oauth ruby gem, you can build a user token and do the necessary get, put, and post requests using that token. Since Facebook supports OAuth tokens (I believe), this might be the best way to do it.

Information on the ruby OAuth gem here

user2276204
  • 257
  • 1
  • 3
  • 9