facebook登录按钮添加到我的应用程序,但一旦用户登录就不会重定向

时间:2013-09-23 07:31:23

标签: javascript facebook html5 facebook-graph-api

我正在开发一个Web应用程序,我已经从developers.facebook.com实现了facebook登录,但问题是,每当用户使用他的facebook凭据登录时,它都不会重定向到我的应用程序,我也试图测试它在我的IDE本地,但即使我无法做到这一点。是否有任何方法来使它我也在寻找注销选项,因为我想在用户登录后添加注销按钮。任何帮助将不胜感激。提前谢谢。

这是我的登录代码:

HTML:

<div id="fb-root"></div>

<div class="fb-login-button" data-width="500"></div>

和我的JS代码:

    window.fbAsyncInit = function() {
  // init the FB JS SDK
   FB.init({
  appId      : '425369200906567',                        // App ID from the app dashboard
  channelUrl : 'channel.html', // Channel file for x-domain comms
  status     : true,                                 // Check Facebook Login status
  xfbml      : true                                  // Look for social plugins on the page
   });

   // Additional initialization code such as adding Event Listeners goes here
   };

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

      (function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=425369200906567";
  fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

1 个答案:

答案 0 :(得分:0)

如果您想在用户登录到您的应用后执行某些操作(您的案例重定向到另一个页面应用页面,则可以使用response.authResponse来执行此操作

FB.login(function(response) {
      if (response.authResponse) {
          // when the user logs in! & gives permission
          // Do something
         alert('Change this alert to "windows.location"')
      } else {
          // when the user doesn't give the required permissions
          // Do something 
        alert('User canceled login or did not fully authorize the app.');

      }
    }, { scope: 'user_photos, publish_stream' }); // App's permission

Fiddle