twitter - 如何在 React Native 中使用 Firebase Twitter 身份验证?

标签 twitter firebase react-native firebase-authentication

如何在 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 中编写一个扩展程序才能在不使用浏览器样式的流程的情况下完成您想做的事情。

关于twitter - 如何在 React Native 中使用 Firebase Twitter 身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30795853/

相关文章:

android - 如何在 Firebase Analytics 中添加屏幕跟踪/计时?

javascript - 即使 Prop 改变了,屏幕也不会重新渲染?

javascript - 如何使用 tcomb-form-native 将电子邮件验证添加到字段?

ios - ios 中的回调未返回进行身份验证

ios - 如何在Twitter中将URL发送给 friend

ios - 如何让我的应用程序在 Twitter 上列入白名单以获取用户电子邮件?

java - Twitter4j - 超出速率限制

java - 如何从 Firebase 数据库检索纬度和经度到 Android map 应用程序

javascript - Vuejs - 如何使用单个表单添加和编辑

javascript - 无法读取未定义的属性 'containerColor'(制作 react 性自定义组件)