okm*_*dhr 8 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.
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
和
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);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
当我使用时authWithOAuthRedirect
,发生了一个错误
undefined is not an object (evaluating 'window.location.href')
Run Code Online (Sandbox Code Playgroud)
当我使用时authWithOAuthPopup
,什么也没发生.
我该如何解决这个问题?还是不可能?
这是针对网络的 Firebase Twitter 集成。尽管它有祖先并且使用 JavaScript,但 React Native 绝不是 Web;它是 Web 的一部分。你没有 DOM,你没有浏览器,所以你没有能力重定向当前窗口,这似乎就是这段代码想要做的。
因此,为了回答您的问题,不可能按原样使用该库。您可能会发现您必须在 Obj-C 中编写一个扩展才能在不使用浏览器样式流程的情况下完成您想做的事情。
归档时间: |
|
查看次数: |
2854 次 |
最近记录: |