错误FB.login()在angularJS中的FB.init()之前调用?

时间:2018-03-25 10:23:04

标签: angularjs

<html ng-app="faceBoookLogin">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script type="text/javascript" src="fbController.js"></script>
<script type="text/javascript">
    window.fbAsyncInit = function() {
      FB.init({
      appId            : 'your-app-id',
      autoLogAppEvents : true,
      xfbml            : true,
      version          : 'v2.12'
      });
    };

(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 = "https://connect.facebook.net/en_US/sdk.js";
  fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));

</script>
<body ng-controller="fbController">
    <button type="button" ng-click="FBLogin()">
      Login With Facebook
     </button> 
</body>
</html>

var app = angular.module("faceBoookLogin", []);
app.controller("fbController", ['$scope', function($scope){
	
//call FBLogin for login with fb
$scope.FBLogin = function(){
  FB.login(function(response) {
    if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');

     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });
    } else {
     console.log('User cancelled login or did not fully authorize.');
    }
  });
}

}]);

大家好, 我用facebook js实现了登录的功能,但我得到了上面的错误。我已经包含了all.js一次,但我仍然收到此错误“FB.login()在调用FB.init()之前调用”当我点击登录按钮告诉任何人如何解决这个问题?

0 个答案:

没有答案