Facebook PHP SDK错误
我已使用facebook开发者帐户注册了新应用程序。在下面的教程中,我有以下代码:Facebook PHP SDK错误,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我已使用facebook开发者帐户注册了新应用程序。在下面的教程中,我有以下代码: <?php // Remember to copy files from the SDK's src/ directory to a // directory in your application on the server, such as php-sdk/ require_once('facebook/facebook.php'); $config = array(
<?php
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('facebook/facebook.php');
$config = array(
'appId' => 'xxxxxxxxxxxx',
'secret' => 'yyyyyyyyyyyyyy',
'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?php
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$user_profile = $facebook->api('/me','GET');
echo "Name: " . $user_profile['name'];
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
</body>
</html>
如何修复它?我也遇到了同样的问题,我发现我的“重定向uri”和“有效的OAuth重定向uri”不匹配。
在我的代码中,我设置了:
redirect_uri = "http://www.website.com/validate.php";
但在我的Facebook应用程序中,我设置了有效的OAuth重定向URI:http://website.com/validate.php
我所缺少的只是“www”。因此,我在我的Facebook应用程序中添加了另一个有效的OAuth重定向URI:
http://www.website.com/validate.php
我像魔术一样为我工作。
希望对您有所帮助。在仪表板上,您是否添加了
buzzsu.com
或www.buzzsu.com
?这很重要,好吧!我为www.buzzsu.com编辑了应用程序设置。然后在firefox中,我键入了buzzsu.com,但它不起作用,在我尝试键入www.buzzsu.com后,它起作用了。有什么问题?
http://www.website.com/validate.php