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

前端之家收集整理的这篇文章主要介绍了如何使用React Native使用Firebase Twitter身份验证?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用React Native使用Firebase Twitter身份验证?

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

  1. var Firebase = require("firebase");
  2.  
  3. var App = React.createClass({
  4.  
  5. render: function() {
  6. return (
  7. <View>
  8. <Text onPress={this._handlePress}>
  9. Twitter login
  10. </Text>
  11. </View>
  12. );
  13. },_handlePress: function () {
  14. var myApp = new Firebase("https://<myapp>.firebaseio.com");
  15.  
  16. myApp.authWithOAuthRedirect("twitter",function(error) {
  17. if (error) {
  18. console.log("Login Failed!",error);
  19. } else {
  20. // We'll never get here,as the page will redirect on success.
  21. }
  22. });
  23.  
  24. }
  25.  
  26. });

  1. var Firebase = require("firebase");
  2.  
  3. var App = React.createClass({
  4.  
  5. render: function() {
  6. return (
  7. <View>
  8. <Text onPress={this._handlePress}>
  9. Twitter login
  10. </Text>
  11. </View>
  12. );
  13. },_handlePress: function () {
  14. var myApp = new Firebase("https://<myapp>.firebaseio.com");
  15.  
  16. myApp.authWithOAuthPopup("twitter",function(error,authData) {
  17. if (error) {
  18. console.log("Login Failed!",error);
  19. } else {
  20. console.log("Authenticated successfully with payload:",authData);
  21. }
  22. });
  23.  
  24. }
  25.  
  26. });

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

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

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

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

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

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

猜你在找的React相关文章