2016-04-29 16 views
0

私はイオンベースのアプリケーションにfirebaseを使用してFacebookのログイン後にユーザーのメールや好きなことに直面している。 また、Facebookの表示名やその他の情報を取得しても、ログインページが更新される代わりにダッシュボードページにリダイレクトされません。私はstackoverflowと他の魔法に別の記事を読むが、私は立ち往生している。これらの2つの問題を解決するために私を助けてください。すぐ後にログインfacebookで検証ダッシュボードにユーザーをリダイレクトする方法をユーザー ** 2の電子メールや同類を取得する方法** 1 )**)** .. ここでコードFacebookベースログインイオンベースfirebaseを使用して

****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); 
}) 

答えて

5

があることを確認してください

.controller('loginCtrl', function($scope,facebookUrl,$state){ 
下に示すように、コントローラにこの定数「facebookUrl & 『$状態を』注入という

.constant('facebookUrl', 'https://rjrestaurantapp.firebaseio.com'); 

ようなあなたのアプリの中でどこにでもそれを使用する定数

その後、あなただけの

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'); 
    } 
    }) 
}}) 

と電子メールのために..あなたは、Facebookの認証後にリダイレクトする状態の名前を与える必要があり、あなたが最初にこれらの情報が対象に示されていることを確認する必要が好き成功した認証後authData ..

私は、.factory( "認証"、機能($ firebaseAuth)として工場出荷時のコードを追加して、慎重にhttps://www.firebase.com/docs/web/guide/login/facebook.html

+0

このドキュメントをお読みください{ VAR usersRef =新Firebase(「HTTPS//*********.firebase***.****/**** "); return $ firebaseAuth(usersRef); })私は定数はある程度同じアプローチだと思いますが、まだauthDataはユーザーのメールに関する情報を共有していないと思います... –

+0

@AftabKhan firebaseでfacebookを使用して正常に認証された場合、authDataにはfacebook.idというfacebook.idというプロパティが含まれている必要があります。 displayNameとfacebook.emailなど... ログインや認証に成功したかどうかを確認してください。 認証時にauthDataをコンソールにしてください。必要なプロパティを見つけるのに役立ちます。 –

+0

facebook.displayNameのような他のすべての情報はfacebook.email –

関連する問題