0

I am trying to use Jspm.io and Facebook SDK in my code. Here is how my index.html file looks like. When i try to call FB.api('/me') in main.js file, nothing happens.. I am able to call FB.getLoginStatus() though but there is no response or callback for FB.api function. Can anyone tell what the issue might be.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>HyPost</title>
</head>

<body>

  <script src="../jspm_packages/system.js"></script>
  <script src="config.js"></script>

  <script>
    // Load Facebook Script async
    (function(d, s, id){
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {return;}
      js = d.createElement(s); js.id = id;
      js.src = "http://connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

    // When facebook SDK is loaded.
    window.fbAsyncInit = function() {
      FB.init({
        appId      : '158281507845137',
        xfbml      : true,
        version    : 'v2.4',
        status     : true,
      });
      //Import Application
      System.import('./js/main');
    };
  </script>

</body>

</html>

Main.js

import Backbone from 'backbone';
import Marionette from 'marionette';

// Create a New Marionete Application.
let myApp= new Marionette.Application();

myApp.on('before:start', function(opts) {

    // Print Login Status data.
    FB.getLoginStatus(function(res) {
        console.log(res);
    });

    // Not getting called.
    FB.api('/me', function(res) {
        console.log(res);
    });
});

myApp.start({});
  • The following FB code run outside the block, but not working inside before:start callback function. I am not sure why. – Rahul Garg Sep 10 '15 at 07:56
  • Is there any chance that the commands are running in parallel so that /me is being called before your login status is confirmed? Can you put the /me in the callback of a successful getLoginStatus instead? – Hey Darren Sep 18 '15 at 09:54

0 Answers0