Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook login in a Ruby on Rails application

I'm developing a Ruby on Rails application using the Facebook flogin button with JavaScript.

My code:*

<fb:login-button perms="email" onlogin="createFbSession();"></fb:login-button>

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>

<script>
    FB.init({
        appId:"xxxxxxx", cookie:true,
        status:true, xfbml:true
    });
    function createFbSession() {
        FB.getLoginStatus(function(response) {
            if (response.session) {
                window.location = "<%= fb_login_path %>";
            }
        });
    }
</script>

When I click on the flogin button, sometimes I receive the following error in the popup window:

An error occurred. Please try again later.

What does it mean?

like image 733
Marco Antelmi Avatar asked Nov 06 '22 00:11

Marco Antelmi


1 Answers

You could use omniauth which lets you use facebook/twitter/openid etc... in ruby without having to use a js library linked in from facebook.

Railscasts have a great episode on a simple onmiauth setup which is well worth a watch and because omniauth returns similar data for all providers just change twitter to facebook and you should be fine.

Omniauth also allows for multiple providers in the same login system, as some people (myself included) prefer to use twitter so enforced facebook login would put me off.

like image 147
Arcath Avatar answered Nov 09 '22 07:11

Arcath