尝试使用php登录facebook时出错
我正在尝试使用facebook php sdk创建简单的php登录。我正在使用facebook开发者网站上的php代码示例:尝试使用php登录facebook时出错,php,facebook,facebook-php-sdk,Php,Facebook,Facebook Php Sdk,我正在尝试使用facebook php sdk创建简单的php登录。我正在使用facebook开发者网站上的php代码示例: <?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('php-sdk/facebook.php');
<?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('php-sdk/facebook.php');
$config = array('appId' => 'YOUR_APP_ID','secret' => 'YOUR_APP_SECRET', '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 {
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!'
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
// Give the user a logout link
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} 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( array(
'scope' => 'publish_stream'
));
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, so print a link for the user to login
// To post to a user's wall, we need publish_stream permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
</body>
</html>
我也试过网上的几个样品,结果总是出现同样的问题。在我从Facebook授予权限后,Facebook应该将页面返回到我的页面,但它会抛出一个错误。这是从我的母语翻译过来的错误,因此可能与实际的英语版本略有不同:错误此功能目前不可用:错误处理此请求。请稍后再试。在URL中有错误代码=2和错误消息=如果这有帮助吗?我已经在Facebook应用程序页面中配置了我的应用程序id和应用程序机密,其中还设置了显示名称、电子邮件地址、域和站点URL
另外,在代码中,我为SDK和app_id以及secret_id设置了正确的目录
让我想知道我在Facebook应用程序中是否有错误的个人资料?我尝试的每一个代码都会给出相同的错误。我试过与几个不同的人。在用户Facebook中,“应用程序”部分显示我的应用程序名称和给定权限。很可能这是一个简单的问题,我只是没有看到,再次…,问题是我的应用程序不是公共的。为什么要花几个小时才能找到问题,而当被问到这里时,你们会立即自己发明解决方案D