开发者

Facebook Connect: Redirecting to special URL after getting email permission

Within my application I ask users for their email permission:

<fb:login-button perms="email">Give me yo开发者_运维百科ur email</fb:login-button>

The popup open's and the user allows it.

Now I want to redirect the user to a spcial link/page where I have some code which get's the email from facebook. How to do that?

This is what I have as JS code so for, it's to login:

FB.Event.subscribe('auth.login', function() {
    window.location.reload();
});

I tried "auth.sessionChange" and "auth.statusChange" events, but they also fire on login/logut.

All I need are own callback functions for each FB button I think!?

thx


OK, then try this:

FB.login(function(result) {
  if(result.session) {
    location.href = '/login_successful.php'; // Or whatever
  }
},
{perms: 'email'});


My dear capture the login event and redirect the user where do you want like this


 
   window.fbAsyncInit = function() {
   FB.init({appId: "XXXXXX",
            status: true,
            cookie: true,
            xfbml: true});

    FB.getLoginStatus(function(response) {
      if (response.session) {
        //here you can redirect the user where do you want to redirect it
        self.location.href="http://www.yoursite.com/login.php";
      } else {

        }
    }); 
    FB.Event.subscribe("auth.login", function(response) {
    window.location.reload();
      });
FB.Event.subscribe("auth.logout", function(response) {
    // to logout

    self.location.href="http://www.yoursite.com/logout.php";
      });
     };
   (function() {
     var e = document.createElement("script");
     e.type = "text/javascript";
     e.src = document.location.protocol +
     "//connect.facebook.net/en_US/all.js";
     e.async = true;
     document.getElementById("fb-root").appendChild(e);
   }());
   


You will need to use the Graph API to get the users email address. More info about Graph here


both answers where usefull (sorry, cant vote up because of reputations - I'm a new user), but I solved it this way:

<script type="text/javascript">
                function chkmyperm() {
                jQuery.get("/user/chkmyperm", function(data){
                    if(data==1) {
                    window.location.reload();
                    }
                });
                }
            </script>

            <fb:login-button perms="email" onlogin="chkmyperm()">E-Mail Adresse freigeben</fb:login-button>

With the onlogin attribute I callback a own function which checks (with an ajax call, calling php-sdk API) if the user gave me his email permission or not, if so I refresh the page. I did this way because this be behavior should only be on dealing the email permission and not on other events like login/logout.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜