FB未使用angularjs

时间:2017-12-22 11:21:51

标签: angularjs facebook

window.fbAsyncInit = function() {
    FB.init({
      appId            : 'apikey',
      autoLogAppEvents : true,
      xfbml            : true,
      version          : 'v2.10'
    });

    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        console.log('FB Logged in.');
      }
      else if(response.status === 'not_authorized'){
        console.log('FB Not Authorized');
      }
      else {
        console.log("FB Not Connected");
        //FB.login();
      }
    });

  };

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



$scope.authenticateFB = function(facebook){

      FB.login(function(response){
          if(response.authResponse){
            FB.api('/me', 'GET', {
                fields: 'id, email, first_name, last_name, name, picture'
              }, function(response) {
                $scope.$apply(function(){
                  auth.socialLoggedIn(facebook, response)
                    .success(function(res){

                      $scope.name = response.name;
                      $scope.email = response.email;
                      $rootScope.loggedIn = true;

                      //$location.path('/dashboard'); 
                      if(auth.getCurrentUser().children.length > 0){
                        $location.path('/dashboard'); 
                      }else if(res.data.address == "" || res.data.city == ""){
                         $location.path('/infopage/'+res.data.user_id);   
                      }
                      else{
                        $location.path('/profilepage/'+res.data.user_id);   
                      }

                    }).error(function(){
                      $scope.signinfailed = true;
                      notify.message('Error Please try after some time');
                    })

                });
            });
          } else {
            //error
          }
        }, {
            'scope':'email',
            return_scopes: true

      });
   }

//尝试使用facebook登录,但它不起作用我不知道为什么这会产生问题 //可能是检查auth.getCurrentUser或其他请指导

的问题

但错误是FB未定义。有什么建议 ?

我猜当发送到仪表板时,它会导致错误

0 个答案:

没有答案