我正在尝试使用 javascript 创建 facebook 连接,这会产生以下错误:
应用程序配置不允许给定 URL。:应用程序的设置不允许一个或多个给定 URL。它必须与网站 URL 或画布 URL 匹配,或者域必须是应用程序域之一的子域。
是不是因为我使用 Localhost 服务器进行测试?我需要购买域来测试这个还是什么?还是我需要在以下代码中进行更改:
我的代码:
<?php
//
// uses the PHP SDK. Download from https://github.com/facebook/php-sdk
include("facebook-php-sdk/src/facebook.php");
//
// from the facebook app page
define('YOUR_APP_ID', '321849981247524');
define('YOUR_APP_SECRET', '49fd00ce6237aff0af08fd8ca25dbc92');
//
// new facebook object to interact with facebook
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
//
// if user is logged in on facebook and already gave permissions
// to your app, get his data:
$userId = $facebook->getUser();
?>
<html>
<head>
<style>body { text-align:center; font-size: 40px }</style>
</head>
<body>
<?php
if ($userId) {
//
// already logged? show some data
$userInfo = $facebook->api('/' + $userId);
echo "<p>YOU ARE: <strong>". $userInfo['name'] ."</strong><br/>";
echo "Your birth date is: ".$userInfo['birthday']."</p>";
} else {
//
// use javaascript api to open dialogue and perform
// the facebook connect process by inserting the fb:login-button
?>
<div id="fb-root"></div>
<fb:login-button scope='email,user_birthday'></fb:login-button>
<?php
}
?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : <?=YOUR_APP_ID?>, //When I gives app ID "321849981247524" or my own created it gives error that it's not valid
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response) {
// ------------------------------------------------------
// This is the callback if everything is ok
window.location.reload();
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
</body>
</html>
当我在浏览器中运行时,它显示 facebook 按钮并单击重定向到新窗口以进行 FB 日志记录,但随后显示上述错误!