0

我无法获取权限对话框以及登录 Facebook 这是我的代码:

<!DOCTYPE html> 
<html> 
<head> 
    <title>My Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.js"></script>

</head> 
<body> 


<div data-role="page">
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'APP_ID', // App ID
      channelUrl : 'http://connect.facebook.net/en_US/all.js', // 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.statusChange', handleStatusChange);
  };

function handleStatusChange(response) {
     document.body.className = response.authResponse ? 'connected' : 'not_connected';

     if (response.authResponse) {
     //  console.log(response);
     FB.api('/me/likes/171099129606813', function(response) {
                        if ( response.data.length === 1 ) { //there should only be a single value inside "data"
                        console.log('You like it');
                        } else {
                        console.log("You don't like it");
                        }
        });

     }
     else
     {
         FB.login(function(response) {
            if (response.status == 'connected') {
                  //console.log(response); 

                    FB.api('/me/likes/171099129606813', function(response) {
                        console.log(response);
                     });

                } else {
                    alert('Not Logged In');
                  // user is not logged in
                }    

        }, {scope: 'email,user_likes'});     
     }
   }
  // 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));
</script>
    <div data-role="header">
        <h1>My Title</h1>
    </div><!-- /header -->

    <div data-role="content">   
        <p>Hello world</p>      
    </div><!-- /content -->

</div><!-- /page -->

</body>
</html>

仍然没有将我带到身份验证页面它正在更改 body 的类名但无法处理 fb 登录

4

2 回答 2

0

这也发生在我身上。FB.login 函数嵌套在回调中。在我的情况下,浏览器阻止了来自 facebook 的弹出页面。当我取消阻止弹出窗口时,它很好。

于 2013-06-18T18:59:09.810 回答
0

今天我花了一段时间才明白 window.fbAsyncInit 方法不会在某些移动浏览器上触发(实际上是在我公司的所有移动设备上)。你需要做的是添加这样的东西:

var called = false;
window.fbAsyncInit = function () {
    if (called) return;
    called = true;

    // here the fb code
}

if (!called) window.fbAsyncInit();
于 2012-09-01T19:32:52.067 回答