Javascript OAuth无法使用传输

Javascript OAuth无法使用传输,javascript,angularjs,firebase,angularfire,google-oauth,Javascript,Angularjs,Firebase,Angularfire,Google Oauth,我正试图用谷歌登录到我的firebase项目中,我在firebase的弹出和重定向功能中遇到了传输不可用错误。是因为我在当地工作还是我在这里做错了什么 var app = angular.module('WOM', ["firebase"]); app.controller('SampleCtrl', ['$scope', '$firebaseObject', '$firebaseAuth', function($scope, $firebaseObject, $firebaseAuth){ v

我正试图用谷歌登录到我的firebase项目中,我在firebase的弹出和重定向功能中遇到了传输不可用错误。是因为我在当地工作还是我在这里做错了什么

var app = angular.module('WOM', ["firebase"]);
app.controller('SampleCtrl', ['$scope', '$firebaseObject', '$firebaseAuth', function($scope, $firebaseObject, $firebaseAuth){
var ref = new Firebase('https://who-owes-me.firebaseio.com/'); //Where data is stored
var auth = $firebaseAuth(ref);

$scope.login = function() {
    $scope.authData = null;
    $scope.error = null;

    auth.$authWithOAuthPopup("google").then(function(authData){
        $scope.authData = authData;
    }).catch(function(error){
        $scope.error = error;
    });
}

$scope.data = $firebaseObject(ref); //assign data to scope

$scope.data.$loaded()
    .then(function(){
        console.log($scope.data);
    })
    .catch(function(err){
        console.error(err);
    })
}]);

这可能意味着您正在使用文件系统。

为了运行Auth方法,您必须在真正的服务器上工作。一般来说,使用本地服务器而不是文件系统进行开发是一种很好的做法,因为这更接近于生产环境的行为


在firebase中开发angular应用程序时,我遇到了同样的问题

它在浏览器中运行良好,但当在iOS webview应用程序中打开它时,它在尝试登录facebook时开始变得不可用

首先,我进入了的firebase文档,这让我进入了
authWithOAuthRedirect
,但它也不起作用

在此之后,我发现我使用的是一个关于
authWithOAuthRedirect
,这个问题在2.4.1版上得到了解决因此,请确保您正在使用版本2.4.2或将应用程序迁移到firebase 3.0

我仍然遇到了另一个问题,在对此进行了更多的研究之后,我开始将
onAuth
与我的身份验证一起使用<每次用户成功进行身份验证时,都会调用code>onAuth。这让一切变得容易多了

因此,我的登录控制器现在看起来如下所示:

.controller('LoginCtrl', ['$scope', 'Auth', 'fbutil', 'FBURL', function($scope, Auth, fbutil, FBURL) {

    var ref = new Firebase(FBURL);
    ref.onAuth( function(authData){
      if (authData){
        //User authenticated. Do your logic.
      }
    });

    $scope.fbLogin = function() {
      ref.authWithOAuthPopup("facebook", function(error, authData) {
          if (error){
            if (error.code === "TRANSPORT_UNAVAILABLE") {
              Auth.$authWithOAuthRedirect("facebook", function(error) {
                console.log(error);
              });
            }
            $scope.err = errMessage(error);
          }
      });
    };
})

令人惊叹的!感谢david,http服务器的另一种选择是使用Firebase CLI的
Firebase serve
命令。@david east我在Firebase中有一个angular应用程序,它在浏览器中运行良好。但我为它创建了一个iOS webview应用程序。当我使用iOS应用程序登录facebook时,我发现TRANSPORT_不可用。有什么想法吗?@约翰,事实上我有。给我几个小时,我会在这个主题中给出一个描述我的解决方案的答案。@John看一下我的答案。希望能有帮助。