【问题标题】:Ionic firebase facebook authIonic firebase facebook auth
【发布时间】:2017-03-10 17:02:28
【问题描述】:

我有 Facebook 登录页面(我正在使用 Firebase Auth),当我在设备上运行我的应用并单击登录按钮时,我收到错误消息:

运行此应用程序的环境不支持此操作。 “location.protocol”必须是 http 或 https 并且必须启用网络存储。

错误代码是:

auth/operation-not-supported-in-this-environment

如果我在我的谷歌浏览器中运行这个应用程序,它的效果很好。问题出在哪里?

谢谢。

登录代码:

var provider = new firebase.auth.FacebookAuthProvider();
    firebase.auth().signInWithPopup(provider).then(function(result) {
      // This gives you a Facebook Access Token. You can use it to access the Facebook API.
      var token = result.credential.accessToken;
      // The signed-in user info.
      var user = result.user;
      console.log(user);
      // ...
    }).catch(function(error) {
      // Handle Errors here.

      var errorCode = error.code;
      var errorMessage = error.message;
     console.log(errorMessage);
     console.log(errorCode);
      var email = error.email;
      // The firebase.auth.AuthCredential type that was used.
      var credential = error.credential;
      // ...
    });

【问题讨论】:

  • signInWithPopup 目前在 Cordova 中不受支持。作为一种解决方法,您可以为 Cordova 使用 Facebook 登录库,然后使用访问令牌调用 signInWithCredential()。
  • 我该怎么做?你有一个例子吗? @ChanningHuang

标签: cordova firebase ionic-framework firebase-authentication


【解决方案1】:

正如 Channing 所说,目前 Cordova 不支持此功能。 您需要使用 Cordova 插件进行 facebook 登录。 成功后,您将获得 OAuth 2 访问令牌或 id 令牌。 然后,您使用 web sdk 初始化身份验证凭据并调用 signInWithCredential:

firebase.auth().signInWithCredential(firebase.auth.FacebookAuthProvider.credential(fbAccessToken)).then(function(user) {
  // The facebook user is now signed in.
}).catch(function(error) {
  // Some error happened!
});

要获取 fb 访问令牌,您可以使用我找到的以下插件:https://github.com/Wizcorp/phonegap-facebook-plugin

【讨论】:

  • 我可以获得访问令牌,但承诺似乎不起作用。没有解决也没有发现任何错误。不知道如何调试它,因为它是在模拟器中运行的。还是谢谢。
  • 好的,最后我在 android sdk 中发现了 'monitor' 来调试模拟器。错误非常愚蠢,我没有在组件中导入 firebase。 Monitor 向我展示了 Reference error firebase 之类的东西......无论如何,你的答案非常有用,是发现很多东西的关键。非常感谢。
猜你喜欢
  • 2018-01-24
  • 2017-09-23
  • 1970-01-01
  • 2016-12-07
  • 2017-07-21
  • 2016-12-05
  • 1970-01-01
  • 2016-09-20
  • 1970-01-01
相关资源
最近更新 更多