【问题标题】:How to logout in the facebook with cordova ionic application?如何使用科尔多瓦离子应用程序在 facebook 中注销?
【发布时间】:2016-02-21 09:23:41
【问题描述】:

我用这个教程https://github.com/nraboy/ng-cordova-facebook-example但是这个例子没有实现注销功能,我添加这个代码:

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>

但我找到了任何结果

【问题讨论】:

  • facebook 示例?使用你自己的名字应用程序

标签: android angularjs facebook ionic-framework cordova-plugins


【解决方案1】:

您的代码是无效的 javascript...很多解析错误。此外,您不需要另一个控制器来注销。用户登录的事实是基于本地存储中的访问令牌,只需擦除它并转到另一个状态.. 将您的配置文件控制器更新为:

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>

【讨论】:

    猜你喜欢
    • 2018-02-08
    • 2015-07-23
    • 2013-12-25
    • 1970-01-01
    • 2016-08-30
    • 2015-12-08
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多