![](/img/trans.png)
[英]Ionic - App works fine on browser and iOS simulator but not in android simulator
[英]Ionic Firebase Facebook login works fine in browser, but not on Android
我對Ionic不太熟悉,在使用android平台上的ionic框架進行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.
});
};
})
解決了!
原來,我只是在該項目的config.xml中丟失了一個Firebase標記。老實說,這很愚蠢,希望它對遇到相同問題的人有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.