我正在构建一个 Facebook 应用程序,目前它处于沙盒模式。我的代码:-
索引.php
<?php
ob_start();
@session_start();
require 'facebook.php';
include_once('config.php');
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => SECRET_KEY,
));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
if (!empty($user_profile )) {
# User info ok? Let's print it (Here we will be adding the login and registering routines)
$username = $user_profile['name'];
//echo '->'.$username;exit;
$uid = $user_profile['id'];
$email = $user_profile['email'];
@session_start();
//$_SESSION['id'] = $userdata['id'];
$_SESSION['oauth_id'] = $uid;
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['oauth_provider'] = 'facebook';
header("Location: home.php");
?>
<?php
} else {
# For testing purposes, if there was an error, let's kill the script
die("There was an error.");
}
} else {
# There's no active session, let's generate one
$login_url = $facebook->getLoginUrl(array( 'scope' => 'email'));
header("Location: " . $login_url);
}
?>
在这里,我检查用户是否登录,如果是登录用户,则重定向到 home,php,否则重定向到 facebook 的登录页面。
但是当我在 Facebook 上运行我的应用程序时,它在控制台上抛出错误:-
拒绝显示文档,因为 X-Frame-Options 禁止显示,因为它将“X-Frame-Options”设置为“DENY”
我也尝试过this https://stackoverflow.com/questions/9491540/refused-to-display-document-because-display-forbidden-by-x-frame-options解决方案,但它不起作用
您不能在任何类型的框架内显示登录对话框 - 这是一种反网络钓鱼措施,用户应该始终能够验证他们显示的登录对话框确实来自 facebook.com,而不是从 facebook.com 加载的虚假登录对话框任何其他网站。
您必须在顶部窗口实例中重定向到它。这无法在服务器端完成,因此您必须使用 JavaScript:
<script>top.location.href = "…";</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)