我制作了一个以圣诞为主题的Facebook应用程序,我想在页面上添加一个标签,但我遇到了一些使应用程序无法使用的问题。
网站网址如下:https://mariusvaduva.com/bradbattle/
如果我第一次登录那里我没有遇到任何问题,但不幸的是,当我直接在Facebook页面标签上测试时,作为新用户,登录后我收到一个空白页而不是iframe,并出现以下错误:
Refused to display in a frame because it set 'X-Frame-Options' to 'DENY'.
这是我获取登录网址的方式:
session_start();
require_once 'php/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'XXXXXX',
'app_secret' => 'XXXXXX',
'default_graph_version' => 'v2.8'
]);
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl('https://mariusvaduva.com/bradbattle/callback.php');
这就是我显示链接的方式:
<div id="login_container">
<?php echo '<a href="' . htmlspecialchars($loginUrl) . '"><img id="login_btn" src="img/login.png"></a>'; ?>
</div>
我尝试了一些建议,包括使用X-Frame-Options: ALLOW-FROM https://www.facebook.com/
添加.htaccess文件,但没有成功。
我做错了什么?还有另一种处理方法吗?我真的很想在本周末做好准备。任何帮助或指导都非常受欢迎。
P.S。这是我的回调文件,以防它有用:
session_start();
require_once 'php/Facebook/autoload.php';
require_once 'php/classes/class.database.php';
$fb = new Facebook\Facebook([
'app_id' => 'XXXXXX',
'app_secret' => 'XXXXXX',
'default_graph_version' => 'v2.8'
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (!isset($accessToken)) {
if ($helper->getError()) {
header('HTTP/1.0 401 Unauthorized');
echo "Error: " . $helper->getError() . "\n";
echo "Error Code: " . $helper->getErrorCode() . "\n";
echo "Error Reason: " . $helper->getErrorReason() . "\n";
echo "Error Description: " . $helper->getErrorDescription() . "\n";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'Bad request';
}
exit;
}
echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());
$oAuth2Client = $fb->getOAuth2Client();
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
echo '<h3>Metadata</h3>';
var_dump($tokenMetadata);
$tokenMetadata->validateAppId('1849207942031149');
$tokenMetadata->validateExpiration();
if (!$accessToken->isLongLived()) {
try {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
} catch (Facebook\Exceptions\FacebookSDKException $e) {
echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>\n\n";
exit;
}
echo '<h3>Long-lived</h3>';
var_dump($accessToken->getValue());
}
$_SESSION['fb_access_token'] = (string)$accessToken;
try {
$response = $fb->get('/me?fields=id,name', $_SESSION['fb_access_token']);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$user = $response->getGraphUser();
$db = new Database();
$sql = 'SELECT id FROM users WHERE id = "%s" LIMIT 1';
$db->prepare($sql,array($user['id']));
$data = $db->execute();
if (empty($data)) {
$sql = 'INSERT INTO users (id, name) VALUES ("%s","%s")';
$db->prepare($sql,array($user['id'],$user['name']));
$data = $db->execute();
}
$_SESSION['user_id'] = (string)$user['id'];
$_SESSION['user_name'] = (string)$user['name'];
header('Location: https://mariusvaduva.com/bradbattle/bradbattle.php');
exit;