如何使用React Native使用Firebase Twitter身份验证? [英] How to use Firebase Twitter Authentication with React Native?
问题描述
如何使用Firebase Twitter身份验证与React Native?
我试过以下两个代码,参考 https://www.firebase.com/docs/web/guide/login/twitter.html
var Firebase = require(firebase);
$ b $ var App = React.createClass({
render:function(){
return(
< View>
< Text onPress = {this._handlePress}>
Twitter登入
< / Text>
< / View>
);
},
_handlePress:function(){
var myApp = new Firebase(https://< myapp> .firebaseio.com);
myApp.authWithOAuthRedirect(twitter (错误){
if(error){
console.log(Login Failed!,error);
} else {
//我们永远不会到这里,因为页面会重定向成功
}
});
}
});
和
var Firebase = require(firebase);
$ b $ var App = React.createClass({
render:function(){
return(
< View>
< Text onPress = {this._handlePress}>
Twitter登入
< / Text>
< / View>
);
},
_handlePress:function(){
var myApp = new Firebase(https://< myapp> .firebaseio.com);
myApp.authWithOAuthPopup(twitter (error),
console.log(Login Failed!,error);
} else {
console.log ,authData);
}
});
}
});
当我使用 authWithOAuthRedirect
时,发生错误像
undefined不是一个对象(评估'window.location.href')
当我使用 authWithOAuthPopup
时,什么也没有发生。
我该如何解决这个问题?
或是不可能的?
这是网页的Firebase Twitter整合。尽管它的祖先和它的JavaScript的使用,React Native绝不是网络;你没有一个DOM,你没有浏览器,所以你没有能力重定向当前的窗口,这似乎是这个代码试图做的。
所以,要回答你的问题,就不可能使用这个库。你可能会发现你必须在Obj-C中编写一个扩展,才能在不使用浏览器风格的流程的情况下完成你想做的事情。
How to use Firebase Twitter Authentication with React Native?
I tried both of the code below in reference to 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.
}
});
}
});
and
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);
}
});
}
});
When I use authWithOAuthRedirect
, an error occurred like
undefined is not an object (evaluating 'window.location.href')
When I use authWithOAuthPopup
, nothing happened.
How can I solve the question? Or is it not possible?
This is the Firebase Twitter integration for the web. Despite its ancestry and its use of JavaScript, React Native is in no way the web; you don't have a DOM, you don't have the browser and so you don't have the ability to redirect the current window, which seems to be what this code is trying to do.
So, to answer your question, using this library as it is will not be possible. You might find you have to write an extension in Obj-C to do what you want to do without using the browser-style flow.
这篇关于如何使用React Native使用Firebase Twitter身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!