2013-02-06 134 views
0

我想在用户点击链接后显示Facebook登录/注册框,但它不起作用。解析应该用自己的init函数加载FB SDK,并且应该用另一个自己的函数显示登录框。我直接从他们的文档复制并粘贴了这些代码,所以我不认为这是一个语法问题。我也试着在不同的地方初始化Parse SDK,但这似乎并不重要。我知道jquery函数正在工作,因为我已经使用警报函数对其进行了测试,当点击目标链接时它会触发,但登录框不会显示。
我需要解决什么问题?Facebook通过Parse&Javascript登录

>

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

    // Initialize the Parse SDK! 

      Parse.initialize("***********","***********"); 

window.fbAsyncInit = function() { 


    //initialize Facebook SDK via Parse 

     Parse.FacebookUtils.init({ 

     appId  : '***********', // App ID from the App DashboardD 
     channelUrl : '//http://spilot.koding.com/channel.html', // Channel File for x-domain communication 
     status  : true, // check the login status upon init? 
     cookie  : true, // set sessions cookies to allow your server to access the session? 
     xfbml  : true // parse XFBML tags on this page? 
    }); 

    // Additional initialization code such as adding Event Listeners goes here 
     // use Parse SDK to show Facebook login/registration box after user clicks link 

     $("a").click(function(){ 
         Parse.FacebookUtils.logIn(null, { 
        success: function(user) { 
        if (!user.existed()) { 
         alert("User signed up and logged in through Facebook!"); 
        } else { 
         alert("User logged in through Facebook!"); 
        } 
        }, 
        error: function(user, error) { 
        alert("User cancelled the Facebook login or did not fully authorize."); 
        } 
       }); 
     }); 

// Load the SDK's source Asynchronously 
    // Note that the debug version is being actively developed and might 
    // contain some type checks that are overly strict. 
    // Please report such bugs using the bugs tool. 
    (function(d, debug){ 
    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" + (debug ? "/debug" : "") + ".js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document, /*debug*/ false)); 
</script> 

     <div id="header"></div> 

    <div id="findScene"><a href=""><h1>Find</h1></a></div> 
    <div id="startScene"><a href=""><h1>Host</h1></a></div> 

    <div id="footer"></div> 

    </body> 
> 

回答

8
<script type="text/javascript">  
// Initialize the Parse object first. 
Parse.initialize("XXXXXXXXXX", "YYYYYYYYYYYYY"); 

window.fbAsyncInit = function() { 
    Parse.FacebookUtils.init({ 
     appId  : 'ZZZZZZZZZZZZZZZ', 
     status  : true, 
     cookie  : true, 
     xfbml  : true 
    }); 
    Parse.FacebookUtils.logIn(null, { 
     success: function(user) { 
      if (!user.existed()) { 
       alert("User signed up and logged in through Facebook!"); 
      } else { 
       alert("User logged in through Facebook!"); 
      } 
     }, 
     error: function(user, error) { 
      alert("User cancelled the Facebook login or did not fully authorize."); 
     } 
    }); 
}; 

(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> 
+1

但是这是怎么回事通过例如按钮来触发? –