views:

123

answers:

1

Hi,

How do I set a redirect url for FB.login?

I already have this in to render the login popup:

function fbLogin () {
    FB.login(function(response) {
      if (response.session) {
        if (response.perms) {
          window.location = "redirect_url_here"
        } else {
          // user is logged in, but did not grant any permissions
        }
      } else {
        // user is not logged in
      }
    }, {perms:'permissions_here'});
  }

and I have link:

= link_to "Login", "#", :onclick => "fbLogin()"

The problem with this is that it only works for get requests. I need to redirect it to a post request.

Using graph api you could set a redirect uri and get a token from facebook. How do I do this with FB.login?

A: 

Create a form:

<form method="post" action="redirect_url_here" id="fb_form">
</form>

Now using javascript:

function fbLogin () {
    FB.login(function(response) {
      if (response.session) {
        if (response.perms) {
          document.fb_form.submit(); // This should make it work
        } else {
          // user is logged in, but did not grant any permissions
        }
      } else {
        // user is not logged in
      }
    }, {perms:'permissions_here'});
  }
Nazaf