如何在 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/