我在这里使用了说明:https ://parse.com/docs/js_guide#fbusers (Facebook login using Javascript)编写了一个使用 Facebook 身份验证的登录页面。
当我第一次登录时,一切正常(除了控制台中的“FB.init 已被调用”警告。)
当我刷新页面时,我在控制台中看到“用户已连接时调用 FB.login()”错误。但我仍然按预期收到“用户通过 Facebook 登录”消息。
如果我再次点击刷新,我现在会收到一个消息框,上面写着“用户取消了 facebook 登录或没有完全授权”(在代码中定义了 Msgbox),并且在控制台中我现在看到 POST 到https://api .parse.com/1/users返回 400 错误,而不是之前我得到 200 OK。
这是我的 HTML 代码:
<html><head></head><body> <div id="fb-root"></div>
<script src="http://www.parsecdn.com/js/parse-1.2.9.min.js"></script>
<script>Parse.initialize("<key>", "<key>"); // Additional JS functions here
window.fbAsyncInit = function() {
Parse.FacebookUtils.init({
appId : '<id>', // App ID
channelUrl : '<path>/Channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
Parse.FacebookUtils.logIn(null, {
success: function(user) {
if (!user.existed()) {
alert("User signed up and logged in through Facebook!");
} else {
alert("User logged in through Facebook!");
}
},
error: function(user, error) {
alert("User cancelled the Facebook login or did not fully authorize.");
}
});
};
// Load the SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button>
</body> </html>
如果有人能发现问题,我将不胜感激。谢谢!