Facebook登录工作之前需要刷新页面

时间:2014-04-30 09:24:22

标签: facebook angularjs facebook-graph-api facebook-javascript-sdk fbconnect

我在使用facebook登录的应用程序中遇到此问题。

问题

用户需要在Facebook登录提示出现之前按F5 /刷新页面。否则它没有出现,按钮点击没有任何反应。

这是Facebook登录的按钮标签,它可以调用"登录()"方法{angularJS用于}。

 <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代码:

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;
    });
}

}]);

请帮忙解决它!

先谢谢

1 个答案:

答案 0 :(得分:0)

true回调函数之后添加getLoginStatus参数以强制刷新缓存。

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

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