0

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

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

But how is this going to be triggered by a button for example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.