使用javascript时Facebook登录对话框无法打开



我在Mac上使用Eclipse IDE。我创建了一个简单的网页,如果你点击一个按钮,它会要求你登录Facebook。这是我的代码。

<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
function getUserData(response) {
if(response.authResponse) {
FB.api('/me', function(response) {
$('#loginBtn').innerHTML = 'Hello ' + response.name;
});
}
}
window.fbAsyncInit = function() {
FB.init({
appId      : 'xxxxxxxxxx',
cookie     : true,  
xfbml      : true,  
version    : 'v2.8' 
});
FB.getLoginStatus(function(response) {
getUserData(response);
});
};
(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/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

//add event listener to login button
$('#loginBtn').on('click', function() {
FB.login(getUserData, {scope: 'email,public_profile', return_scopes: true});
});
</script>
<button id="loginBtn">Hello</button>
<div id="response">
</div>
</body>
</html>

在这里,我在本地主机上运行它。网址 http://localhost:8080/TestTest/index.jsp..但是当我运行此应用程序时,我在控制台上收到此消息。无法加载网址:此网址的网域不包含在应用的 域。为了能够加载此 URL,请添加所有域和子域 的应用添加到应用设置中的应用域字段。

如何更改我的域名网址?如何将此 URL 的域包含在我的应用中

这意味着您需要添加网址 http://localhost:8080 到您的Facebook应用程序,即您最初创建应用程序 developers.facebook.com。

最新更新