首页 > 解决方案 > 使用facebook登录后如何重定向到html页面

问题描述

下午好,@peter 或 @PeterSmith

15 天以来,我一直在尝试在我的网站上使用“使用 Facebook 登录”。我一直在使用 Facebook 发布的代码,在链接

我对这段代码的问题是,我希望客户在使用他的 Facebook 登录后(通过弹出的窗口)被重定向到我网站上的特定页面,但发生的情况是,在客户使用您的 Facebook 登录后,客户端被重定向到要求他登录的同一页面。

我已经按照我之前提到的链接中解释的步骤进行了操作。有人可以帮助我吗?

我正在使用的代码是这样的:

function statusChangeCallback(response) { // Called with the results from FB.getLoginStatus().
  console.log('statusChangeCallback');
  console.log(response); // The current login status of the person.
  if (response.status === 'connected') { // Logged into your webpage and Facebook.
    testAPI();
  } else { // Not logged into your webpage or we are unable to tell.
    document.getElementById('status').innerHTML = 'Please log ' +
      'into this webpage.';
  }
}


function checkLoginState() { // Called when a person is finished with the Login Button.
  FB.getLoginStatus(function(response) { // See the onlogin handler
    statusChangeCallback(response);
  });
}


window.fbAsyncInit = function() {
  FB.init({
    appId: '{xxxxxxx}',
    cookie: true, // Enable cookies to allow the server to access the session.
    xfbml: true, // Parse social plugins on this webpage.
    version: '{api-version}' // Use this Graph API version for this call.
  });


  FB.getLoginStatus(function(response) { // Called after the JS SDK has been initialized.
    statusChangeCallback(response); // Returns the login status.
  });
};


(function(d, s, id) { // Load the SDK asynchronously
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s);
  js.id = id;
  js.src = "https://connect.facebook.net/en_US/sdk.js";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


function testAPI() { // Testing Graph API after login.  See statusChangeCallback() for when this call is made.
  console.log('Welcome!  Fetching your information.... ');
  FB.api('/me', function(response) {
    console.log('Successful login for: ' + response.name);
    document.getElementById('status').innerHTML =
      'Thanks for logging in, ' + response.name + '!';
  });
}
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();"></fb:login-button>

<div id="status"></div>

<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v6.0&appId=505608310005112&autoLogAppEvents=1"></script>
<div class="fb-login-button" data-width="" data-size="" data-button-type="continue_with" data-layout="rounded" data-auto-logout-link="true" data-use-continue-as="true"></div>

标签: javascripthtmlfacebookfacebook-graph-api

解决方案


推荐阅读