简体   繁体   中英

How to logout in the facebook with cordova ionic application?

i use this tutorial https://github.com/nraboy/ng-cordova-facebook-example but this example is not implemented the function of logout ,i add this code:

facebookExample.controller("LogoutController", function($scope, $http, $localStorage, $location) {
    $scope.logout = function() {
    $cordovaFacebook.logout();

    }, function(error) {
        alert("There was a problem signing in!  See the console for logs");
        console.log(error);
    }
});

profile.html :

<ion-nav-buttons side="right">
    <button class="button icon-left ion-log-out button-stable" ng-controller="LogoutController" ng-click="logout()">Logout</button>
  </ion-nav-buttons>

but i found any result

Your code is invalid javascript... lots of parsing errors. also, you dont need another controller just for logout. The fact that a user is logged in is based upon an access token in localstorage, just wipe it and go to another state.. update your profile controller to this:

facebookExample.controller("ProfileController", function($scope, $http, $localStorage, $location) {

    $scope.init = function() {
        if($localStorage.hasOwnProperty("accessToken") === true) {
            $http.get("https://graph.facebook.com/v2.2/me", { params: { access_token: $localStorage.accessToken, fields: "id,name,gender,location,website,picture,relationship_status", format: "json" }}).then(function(result) {
                $scope.profileData = result.data;
            }, function(error) {
                alert("There was a problem getting your profile.  Check the logs for details.");
                console.log(error);
            });
        } else {
        alert("Not signed in");
        $location.path("/login");
        }
    };

    $scope.logout = function(){
        delete $localStorage.accessToken;
        $location.path("/login");
    };

});

profile.html:

<ion-nav-buttons side="right">
    <button class="button icon-left ion-log-out button-stable" ng-click="logout()">Logout</button>
  </ion-nav-buttons>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM