2

I am facing this issue in my application where facebook login is used.

ISSUE

Users need to press F5/refresh the page before facebook login prompt comes up. otherwise it doesn't come up and nothing happens on button click.

Here is the button tag for Facebook Login, which calls "Login()" method {angularJS is used}.

 <a href="#" class="btn btn-default btn-lg" ng-click="login()"
                   ng-disabled="loginStatus.status == 'connected'"> <i class="fa fa-facebook fa-fw"></i> <span
                        class="network-name">Login Using Facebook</span></a>

AngularJS Code which gets called:

app.controller('DemoCtrl', ['$scope', 'ezfb', '$window', 'PFactory', '$location', function ($scope, ezfb, $window, PFactory, $location) {

updateLoginStatus(updateApiMe);

$scope.login = function () {
    ezfb.login(function (res) {
        /**
         * no manual $scope.$apply, I got that handled
         */
        if (res.authResponse) {
            updateLoginStatus(updateApiMe);
        }
    }, {scope: 'email,user_likes,user_status,user_about_me,user_birthday,user_hometown,user_location,user_relationships,user_relationship_details,user_work_history'});

    $location.path('/view9');
};

$scope.logout = function () {
    ezfb.logout(function () {
        updateLoginStatus(updateApiMe);
    });
};

$scope.share = function () {
    ezfb.ui(
        {
            method: 'feed',
            name: 'angular-easyfb API demo',
            picture: 'http://plnkr.co/img/plunker.png',
            link: 'http://plnkr.co/edit/qclqht?p=preview',
            description: 'angular-easyfb is an AngularJS module wrapping Facebook SDK.' +
                ' Facebook integration in AngularJS made easy!' +
                ' Please try it and feel free to give feedbacks.'
        },
        null
    );
};

var autoToJSON = ['loginStatus', 'apiMe'];
angular.forEach(autoToJSON, function (varName) {
    $scope.$watch(varName, function (val) {
        $scope[varName + 'JSON'] = JSON.stringify(val, null, 2);
    }, true);
});

function updateLoginStatus(more) {
    ezfb.getLoginStatus(function (res) {
        $scope.loginStatus = res;
        $scope.promotion = 'promotion';
        (more || angular.noop)();
    });
}

function updateApiMe() {
    ezfb.api('/me', function (res) {
        $scope.apiMe = res;
    });
}

}]);

Please help resolving it!

Thanks in Advance

1
  • I am facing the same problem. More over to this. I could give my credentials, it getting successfully logged in to Facebook, but the popup window is not getting closed and return to my domain. Simply when I reload the page, it works normal. Also I came to notice that when I come from page.dashboard to $state.go("page.login"); Facebook sdk is not getting loaded. Becase of that ezfb.login() not working.
    – ajin
    Jan 3, 2017 at 10:37

1 Answer 1

0

Add true parameter after getLoginStatus callback function to force refreshing cache.

https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

ezfb.getLoginStatus(function (res) {
 $scope.loginStatus = res;
 $scope.promotion = 'promotion';
 (more || angular.noop)();
}, true);
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.