简体   繁体   English

Facebook登录后如何重定向用户

[英]How to redirect user after facebook login

I am developing a game which requires user to login and then uses the login details to update the leaderboard. 我正在开发一个游戏,要求用户登录,然后使用登录详细信息更新排行榜。 But the problem is that after the user logs in, the login dialog does not get closed automatically and the user is not redirected to the game. 但是问题在于,用户登录后,登录对话框不会自动关闭,并且用户也不会重定向到游戏。 Here is the code which is taken from here 这是从这里获取的代码

window.fbAsyncInit = function() {
      FB.init({
        appId      : 'XXXXXXXXXX',
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true  // parse XFBML
      });

  FB.Event.subscribe('auth.authResponseChange', function(response) {
    shepResponse = response;
    // Here we specify what we do with the response anytime this event occurs. 
    if (response.status === 'connected') 
      testAPI();
    }
    else if (response.status === 'not_authorized') {
      FB.login();
    } else {
      FB.login();
    }
  });
  };

  (function(d){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "http://connect.facebook.net/en_US/all.js";
   ref.parentNode.insertBefore(js, ref);
  }(document));

  function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Good to see you, ' + response.name + '.');
    });
  }

try not wrapping FB.Event.subscribe and testAPI() inside the fbAsyncInit function. 尽量不要在fbAsyncInit函数中包装FB.Event.subscribe和testAPI()。
Also try auth.statusChange instead of auth.authResponseChange 此外,请尝试使用auth.statusChange而不是auth.authResponseChange


var fb_handleStatusChange = function(response) { var fb_handleStatusChange = function(response){
if (response.authResponse) { 如果(response.authResponse){
// user logged in //用户登录
} else { }其他{
// not logged in or logged out //未登录或注销
} }
} }
FB.Event.subscribe('auth.statusChange', fb_handleStatusChange); FB.Event.subscribe('auth.statusChange',fb_handleStatusChange);


Also, i think that the login redirect should be to a page that has this code and is listening for status change. 另外,我认为登录重定向应该是具有此代码并正在侦听状态更改的页面。 I would not redirect back to the same page as the one used for login. 我不会重定向回与用于登录的页面相同的页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM