Facebook javascript SDK FB.login无法在Facebook iFrame中运行

Moh*_*lli 7 javascript facebook facebook-javascript-sdk facebook-authentication

我们正在使用Facebook JavaScript SDK来验证我们的Facebook应用程序.该应用程序使用Canvas URL配置为http://facebook.elgifto.com/Home/Index/.以下是我们用于验证Facebook用户的代码.

    <script type="text/javascript">
          window.fbAsyncInit = function() {
              debugger;
                  FB.init({
                      appId: '<%= ViewData["AppId"].ToString() %>', // App ID
                      channelUrl: '<%= ViewData["ChannelUrl"].ToString() %>', // Channel File
                      status: true, // check login status          
                      cookie: true, // enable cookies to allow the server to access the session
                      xfbml: true,  // parse XFBML
                      oauth: true
                  });

              FB.Event.subscribe('auth.login', function(response) {
                  if (response.status === 'connected') {
                      // the user is logged in and connected to your
                      // app, and response.authResponse supplies
                      // the user’s ID, a valid access token, a signed
                      // request, and the time the access token 
                      // and signed request each expire
                      var uid = response.authResponse.userID;
                      var accessToken = response.authResponse.accessToken;
                      startApp(uid, accessToken);
                  }

              });

          };

          // Load the SDK Asynchronously
          (function(d) {    
              var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
              js = d.createElement('script'); js.id = id; js.async = true;
              js.src = "//connect.facebook.net/en_US/all.js";
              d.getElementsByTagName('head')[0].appendChild(js);
          } (document));




          function startApp(uid, accessToken) {                 
              var baseUrl = '<%= ViewData["AppBaseURL"].ToString() %>';
              var redirectUrl = baseUrl + '?uid=' + uid + '&accessToken=' + accessToken;
              window.top.location.href = redirectUrl;
              //document.location = redirectUrl;
          }          
       </script>
<fb:login-button onlogin="initiateLogin()" perms="email,user_about_me,user_birthday,friends_about_me,friends_birthday">Login with Facebook</fb:login-button>
Run Code Online (Sandbox Code Playgroud)

当访问http://apps.facebook.com/giftguru时,上面的代码在Facebook中不起作用.但是我们可以通过http://facebook.elgifto.com/Home/Index访问它

Jui*_*ter 6

该问题与浏览器弹出窗口阻止有关.(在Facebook之外为你工作的事实可能是因为有时你被允许这样做,对我来说它被阻止以及在应用程序内).

您不应该在没有FB.login用户交互的情况下(如元素click或表单submit)调用,以确保浏览器不会阻止登录窗口.

更新:
你在这里混合很多东西:

  1. Page on http://facebook.elgifto.com/Home/Index正在使用应用程序#316853928368079(此应用程序并且没有namespace!)
  2. 你的OAuth对话的URL有'(撇号)client_id哪个错了!
  3. OAuth Dialog无法正常工作(也可能是应用程序设置,App Domain?)
  4. 位于应用程序http://apps.facebook.com/giftguru申请号83808922524和有错的帆布网址!证明:
    Facebook App Canvas包装

  • @mohang,你的画布没有设置为`http:// facebook.elgifto.com/Home/Index /`但是`http://98.234.246.146:9999/html/home.html`所以我不能看到并检查 (2认同)