Facebook graph api Facebook登录禁用自动重定向

Facebook graph api Facebook登录禁用自动重定向,facebook-graph-api,facebook-login,Facebook Graph Api,Facebook Login,我使用的是facebook登录功能,它运行良好,当我连接到facebook时,重定向会自动完成,但我现在尝试只在用户单击facebook登录按钮时进行重定向,以下是我的代码: 谢谢你的帮助 Ps:对不起,我的英语不好 <button id="fb_login_button" onclick="FB.login(function(){ /* this is a callback function */ }, {scope: 'email,user_birthday,r

我使用的是facebook登录功能,它运行良好,当我连接到facebook时,重定向会自动完成,但我现在尝试只在用户单击facebook登录按钮时进行重定向,以下是我的代码:

谢谢你的帮助

Ps:对不起,我的英语不好

<button id="fb_login_button"
      onclick="FB.login(function(){ /* this is a callback function */ },
      {scope: 'email,user_birthday,read_stream'});
       return false;" class="button button-facelogin" > Via Facebook

</button>



    <script>



  window.fbAsyncInit = function() {
  FB.init({
    appId      : 'XXXXXXXXXXXXX', // App ID
    channelUrl : '//WEBSITE/index.php', // Channel File
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });




  // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
  // for any authentication related change, such as login, logout or session refresh. This means that
  // whenever someone who was previously logged out tries to log in again, the correct case below 
  // will be handled. 
  FB.Event.subscribe('auth.authResponseChange', function(response) {
    // Here we specify what we do with the response anytime this event occurs.

     top.location = window.location = "REDIRECTION URL"



    if (response.status === 'connected' && $GLOBALS["disconected"]=== "false")  {
      // The response object is returned with a status field that lets the app know the current
      // login status of the person. In this case, we're handling the situation where they 
      // have logged in to the app.

      testAPI();


    } else if (response.status === 'not_authorized') {
      // In this case, the person is logged into Facebook, but not into the app, so we call
      // FB.login() to prompt them to do so. 
      // In real-life usage, you wouldn't want to immediately prompt someone to login 
      // like this, for two reasons:
      // (1) JavaScript created popup windows are blocked by most browsers unless they 
      // result from direct interaction from people using the app (such as a mouse click)
      // (2) it is a bad experience to be continually prompted to login upon page load.
      FB.login();



    } else { 
      // In this case, the person is not logged into Facebook, so we call the login() 
      // function to prompt them to do so. Note that at this stage there is no indication
      // of whether they are logged into the app. If they aren't then they'll see the Login
      // dialog right after they log in to Facebook. 
      // The same caveats as above apply to the FB.login() call here.
      FB.login();
    }
  });
  };



  // Load the SDK asynchronously
  (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 = "//connect.facebook.net/en_US/all.js";
   ref.parentNode.insertBefore(js, ref);
  }(document));

  // Here we run a very simple test of the Graph API after login is successful. 
  // This testAPI() function is only called in those cases. 
  function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Good to see you, ' + response.name + '.');
    });
  }
  </script>
通过Facebook
window.fbAsyninit=函数(){
FB.init({
appId:'xxxxxxxxxxxx',//应用程序ID
channelUrl:'//WEBSITE/index.php',//通道文件
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
//这里我们订阅auth.authResponseChangeJavaScript事件
//用于任何与身份验证相关的更改,例如登录、注销或会话刷新
//每当以前注销的用户尝试再次登录时,下面的正确案例
//我们会处理的。
FB.Event.subscribe('auth.authResponseChange',函数(响应){
//在这里,我们指定在发生此事件时如何处理响应。
top.location=window.location=“重定向URL”
if(response.status=='connected'&&$GLOBALS[“disconnected”]=='false”){
//响应对象返回一个状态字段,让应用程序知道当前状态
//此人的登录状态。在本例中,我们正在处理他们
//已登录到应用程序。
testAPI();
}else if(response.status===“未授权”){
//在这种情况下,此人登录了Facebook,但没有登录到应用程序,因此我们呼叫
//FB.login()来提示他们这样做。
//在现实生活中,您不会希望立即提示某人登录
//像这样,有两个原因:
//(1)大多数浏览器都会阻止JavaScript创建的弹出窗口,除非
//使用该应用程序的用户直接交互的结果(如鼠标单击)
//(2)页面加载时不断提示登录是一种不好的体验。
FB.login();
}否则{
//在本例中,此人未登录Facebook,因此我们称其为login()
//函数提示他们这样做。请注意,在此阶段没有任何指示
//他们是否登录到应用程序。如果他们没有,他们将看到登录
//在他们登录Facebook后立即进行对话。
//上面的警告同样适用于这里的FB.login()调用。
FB.login();
}
});
};
//异步加载SDK
(职能(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=“//connect.facebook.net/en_US/all.js”;
ref.parentNode.insertBefore(js,ref);
}(文件);
//在这里,我们在登录成功后运行一个非常简单的Graph API测试。
//此testAPI()函数仅在这些情况下调用。
函数testAPI(){
log('欢迎!获取您的信息…);
FB.api('/me',函数(响应){
log(“很高兴见到你,+response.name+”);
});
}

您可以将代码拆分为两个文件:

Index.php

<button id="fb_login_button" onclick="location.href='facebookLoginPage.php" class="button button-facelogin" > Via Facebook
</button>
通过Facebook
facebookLoginPage.php

<script>

FB.login(function(){ /* this is a callback function */ },{scope: 'email,user_birthday,read_stream'});

  window.fbAsyncInit = function() {
  FB.init({
    appId      : 'XXXXXXXXXXXXX', // App ID
    channelUrl : '//WEBSITE/index.php', // Channel File
    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) {
  top.location = window.location = "REDIRECTION URL"
    if (response.status === 'connected' && $GLOBALS["disconected"]=== "false")  {
      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 = "//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 + '.');
    });
  }
  </script>

login(函数(){/*这是一个回调函数*/},{scope:'email,user_birth,read_stream'});
window.fbAsyninit=函数(){
FB.init({
appId:'xxxxxxxxxxxx',//应用程序ID
channelUrl:'//WEBSITE/index.php',//通道文件
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
FB.Event.subscribe('auth.authResponseChange',函数(响应){
top.location=window.location=“重定向URL”
if(response.status=='connected'&&$GLOBALS[“disconnected”]=='false”){
testAPI();
}else if(response.status===“未授权”){
FB.login();
}否则{
FB.login();
}
});
};
(职能(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=“//connect.facebook.net/en_US/all.js”;
ref.parentNode.insertBefore(js,ref);
}(文件);
函数testAPI(){
log('欢迎!获取您的信息…);
FB.api('/me',函数(响应){
log(“很高兴见到你,+response.name+”);
});
}

我做了,但是当我在facebookLoginPage.php上时,什么也没有发生。你可以查看www.storyser.com/2/demo-login.html谢谢