通过Parse& amp;的Facebook登录Java脚本 [英] Facebook login via Parse & Javascript

查看:81
本文介绍了通过Parse& amp;的Facebook登录Java脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在用户单击链接后显示Facebook登录/注册框,但是它不起作用. Parse应该使用其自己的init函数加载FB SDK,并应该使用其自己的另一个函数显示登录框.我直接从他们的文档中复制并粘贴了该代码,因此我认为这不是语法问题.我也曾尝试在不同的地方初始化Parse SDK,但这似乎无关紧要.我知道jquery函数正在工作,因为我已经使用警报功能对其进行了测试,并且在单击目标链接时会触发它,但是不会显示登录框.
我需要解决什么?

I want the facebook login/register box to be displayed after the user clicks a link, but it won't work. Parse is supposed to load the FB SDK with its own init function and is supposed to display the login box with another one of its own functions. I've copied and pasted that code directly from their documentation so I don't think it's a syntax problem. I've also tried initializing the Parse SDK in different places but it doesn't seem to matter. I know the jquery function is working because I've tested it with an alert function and it fires when I click the targeted link, but the login box won't show.
What do I need to fix?

>

<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>
 >

推荐答案

<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>

这篇关于通过Parse&amp; amp;的Facebook登录Java脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆