Ionic Firebase Facebook登录在浏览器中运行良好,但在Android上运行不正常

时间:2017-07-13 16:10:51

标签: angularjs firebase ionic-framework firebase-authentication

我对Ionic相对较新,我在Android平台上使用离子框架进行Facebook登录时遇到问题。它在浏览器上完美运行(有时当我尝试登录时,第一次尝试不起作用)但是当我在Android上运行项目时,它只是重定向而不会传递到下一页。

我认为问题可能是第一次登录尝试无法获取Facebook用户数据。

这是我的代码:

.controller('LoginCtrl', function (Backand, $state, $rootScope, $scope, LoginService, ID, name) {

$scope.bgs = ["img/welcome-bg.jpg"];

$scope.firebaseFacebookLogIn = function(){

    var provider = new firebase.auth.FacebookAuthProvider();
    provider.addScope('user_birthday');
    provider.addScope('public_profile');
    firebase.auth().signInWithRedirect(provider);

    firebase.auth().getRedirectResult().then(function(result) {
    if (result.credential) {
        // This gives you a Facebook Access Token. You can use it to access the Facebook API.
        var token = result.credential.accessToken;
        var user = result.user;
        var uid = user.providerData[0].uid;
        var nombre = user.providerData[0].displayName;
        localStorage.setItem("Usuario", user);
        localStorage.setItem("ID", uid);
        localStorage.setItem("Nombre", nombre);
        $state.go('app.feed');
    }

    //var user = firebase.auth().currentUser;

    }).catch(function(error) {
        // Handle Errors here.
        var errorCode = error.code;
          alert(errorCode);
        var errorMessage = error.message;
          alert(errorMessage);
        // The email of the user's account used.
        var email = error.email;
          alert(email);
        // The firebase.auth.AuthCredential type that was used.
        var credential = error.credential;
          alert(credential);
        // ...
    });
};

$scope.ID = localStorage.getItem("ID");
$scope.name = localStorage.getItem("name");

$scope.facebookLogOut = function(token){
    firebase.auth().signOut().then(function() {
    // Sign-out successful.
      $state.go('auth.walkthrough');
    }, function(error) {
    // An error happened.
    });

};

})

1 个答案:

答案 0 :(得分:0)

解决了!

事实证明,我只是在项目的config.xml中缺少一个firebase标签。说实话,相当愚蠢,希望它对有同样问题的人有所帮助。