我尝试使用 java 脚本和 html 在 firebase 中登录 facebook。我还创建了一个 facebook 应用程序并在 firebase dashbord 中设置了 app secret 和 app id。 以及 firebase 在他们的文档中所说的 facebook 应用程序中的所有其他设置 但我明白了。
<html>
<head>
<script src='https://cdn.firebase.com/js/client/2.0.4/firebase.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
</head>
<body>
<div id='messagesDiv'></div>
<input type='text' id='nameInput' placeholder='Name'>
<input type='text' id='messageInput' placeholder='Message'>
<script>
var myDataRef = new Firebase('https://fiery-inferno-9432.firebaseio.com/');
myDataRef.authWithOAuthPopup("facebook", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
myDataRef.authWithOAuthRedirect("facebook", function(error, authData) {
if (error) {
console.log("Ridi Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
$('#messageInput').keypress(function (e) {
if (e.keyCode == 13) {
var name = $('#nameInput').val();
var text = $('#messageInput').val();
myDataRef.push({name: name, text: text});
$('#messageInput').val('');
}
});
myDataRef.on('child_added', function(snapshot) {
var message = snapshot.val();
displayChatMessage(message.name, message.text);
});
function displayChatMessage(name, text) {
$('<div/>').text(text).prepend($('<em/>').text(name+': ')).appendTo($('#messagesDiv'));
$('#messagesDiv')[0].scrollTop = $('#messagesDiv')[0].scrollHeight;
};
</script>
</body>
</html>
我得到 登录失败!错误:请求的方法没有可用的登录传输。代码:“TRANSPORT_UNAVAILABLE”消息:“请求的方法没有可用的登录传输。”stack: (...)get stack: function () { [native code ] }set stack: function () { [native code] }proto: dconstructor: function Error() { [native code] }message: ""name: "Error"toString: function toString() } { [native code] }proto: Object
最佳答案
我发现了问题。我必须通过运行文件服务器来运行 html 文件 只需在 cmd 上通过这个
python -m SimpleHTTPServer
然后运行html http://localhost/test.html
关于javascript - 卡住了,用 facebook 和 firebase 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28187136/