如何使用React Native使用Firebase Twitter身份验证?

如何使用React Native使用Firebase Twitter身份验证?

我在参考https://www.firebase.com/docs/web/guide/login/twitter.html时尝试了以下两个代码

var Firebase = require("firebase");

var App = React.createClass({

  render: function() {
    return (
      <View>
        <Text onPress={this._handlePress}>
          Twitter login
        </Text>
      </View>
    );
  },_handlePress: function () {
    var myApp = new Firebase("https://<myapp>.firebaseio.com");

    myApp.authWithOAuthRedirect("twitter",function(error) {
      if (error) {
        console.log("Login Failed!",error);
      } else {
        // We'll never get here,as the page will redirect on success.
      }
    });

  }

});

var Firebase = require("firebase");

var App = React.createClass({

  render: function() {
    return (
      <View>
        <Text onPress={this._handlePress}>
          Twitter login
        </Text>
      </View>
    );
  },_handlePress: function () {
    var myApp = new Firebase("https://<myapp>.firebaseio.com");

    myApp.authWithOAuthPopup("twitter",function(error,authData) {
      if (error) {
        console.log("Login Failed!",error);
      } else {
        console.log("Authenticated successfully with payload:",authData);
      }
    });

  }

});

当我使用authWithOAuthRedirect时,发生了一个错误

undefined is not an object (evaluating 'window.location.href')

当我使用authWithOAuthPopup时,什么也没发生.

我该如何解决这个问题?
或者这不可能吗?

这是针对网络的Firebase Twitter集成.尽管它的祖先和它使用JavaScript,React Native绝不是网络;你没有DOM,你没有浏览器,所以你没有能力重定向当前窗口,这似乎是这段代码试图做的.

因此,要回答您的问题,将无法使用此库.您可能会发现必须在Obj-C中编写扩展来执行您想要执行的操作而不使用浏览器样式的流程.

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...