0 facebook oauth angularjs firebase ionic-framework
在使用firebase进入我的离子应用程序登录facebook后,我面临着收到电子邮件和用户喜欢的问题.在获得Facebook显示名称和用户中的一些其他信息后,没有被重定向到仪表板页面而是登录页面得到刷新.虽然我在stackoverflow和其他的sorces上阅读不同的帖子,但我被卡住了.请帮我解决这两个问题.**1)**如何获取用户的电子邮件和喜欢**2)**如何通过Facebook验证后很快将用户重定向到仪表板..这是代码
****Controller:****
$scope.loginFaceBook = function() {
///alert('fb Login firebase...');
var existingAuthData = Auth.$getAuth();
console.log("existingAuthData : ",existingAuthData);
//console.log("existingAuthData Email : ",existingAuthData.thirdPartyUserData.email);
Auth.$authWithOAuthRedirect("facebook").then(function(authData) {
alert('done 1');
// User successfully logged in
console.log(authData);
$location.path('app/Dash');
}, {
remember: "sessionOnly",
scope: "email,user_likes"
}).catch(function(error) {
if (error.code === "TRANSPORT_UNAVAILABLE") {
Auth.$authWithOAuthPopup("facebook").then(function(authData) {
// User successfully logged in. We can log to the console
// since we’re using a popup here
alert('done 2');
console.log(authData);
$location.path('app/Dash');
}, {
remember: "sessionOnly",
scope: "email,user_likes"
});
} else {
// Another error occurred
console.log(error);
alert('err');
}
});
Auth.$onAuth(function(authData) {
if (authData === null) {
console.log("Not logged in yet");
} else {
console.log("Logged in as", authData.uid);
console.log("Details",authData);
console.log("Name:",authData.facebook.displayName);
alert("Name:",authData.facebook.displayName);
console.log("gender:",authData.facebook.cachedUserProfile.gender);
console.log(" Email : ",authData.facebook.email);
$location.path('app/Dash');
}
$scope.authData = authData; // This will display the user's name in our view
});
};
**App.js**
// Ionic Starter App
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers', 'ngCordovaOauth','firebase','ngFileUpload'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.factory("Auth", function($firebaseAuth) {
var usersRef = new Firebase("https//*********.firebase***.****/****");
return $firebaseAuth(usersRef);
})
Run Code Online (Sandbox Code Playgroud)
请在你的应用程序中随处使用它
.constant('facebookUrl', 'https://rjrestaurantapp.firebaseio.com');
Run Code Online (Sandbox Code Playgroud)
然后在控制器中注入这个常量"facebookUrl&"$ state",如下所示
.controller('loginCtrl', function($scope,facebookUrl,$state){
Run Code Online (Sandbox Code Playgroud)
然后你只需要在facebook认证后给出你要重定向的州的名称..
var ref = new Firebase(facebookUrl);
$scope.fbLogin = function () {
ref.authWithOAuthPopup("facebook", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
$state.go('restaurant');
}
})
}})
Run Code Online (Sandbox Code Playgroud)
对于电子邮件和喜欢,您必须首先确保在成功验证后这些信息显示在authData的对象中.
请仔细阅读本文档https://www.firebase.com/docs/web/guide/login/facebook.html
| 归档时间: |
|
| 查看次数: |
584 次 |
| 最近记录: |