我有一个小的 Facebook 应用程序,它发布了一些预加载的图像。我改变了代码结构,所以我把所有的变量都移到了config.php中,这样会更舒服。但在那之后应用程序不起作用,我真的不知道为什么......在权限对话框之后它一遍又一遍地重新加载自己......有人可以找到这个错误吗?
这是 index.php:
<?php
require 'facebook.php';
require 'config.php';
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret,
'baseUrl' => $baseUrl,
'appBaseUrl' => $appBaseUrl,
'fileUpload' => 'true',
'cookie' => 'true'
));
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
$baseUrl = str_replace('http','https',$baseUrl);
$fbPageURL = str_replace('http','https',$fbPageURL);
$fbPageAppURL = str_replace('http','https',$fbPageAppURL);
}else{
// not https
}
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$like_status = $signed_request["page"]["liked"];
if(!$like_status){
header("Location: notfan.php");
exit;
}
$user = $facebook->getUser();
$params = array(
scope => 'publish_stream,user_photos',
redirect_uri => $fbPageAppURL
);
$loginUrl = $facebook->getLoginUrl($params);
$app_data = $signed_request["app_data"];
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title><?php echo $appName; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
a:link {color:#f1effc;}
a:visited {color:#f1effc;}
a:hover {color:#19378d;}
a:active {color:#19378d;}
a:link {text-decoration: none}
</style>
</head>
<body>
<script type="text/javascript">
function NotInFacebookFrame() {
return top === self;
}
function ReferrerIsFacebookApp() {
if(document.referrer) {
return document.referrer.indexOf("apps.facebook.com") != -1;
}
return false;
}
if (NotInFacebookFrame() || ReferrerIsFacebookApp()) {
top.location.replace("<?= $fbPageAppURL ?>");
}
</script>
<?php if($user){
try {
$user_profile = $facebook->api('/me');
$scope = 'publish_stream,user_photos';
$scope_params = explode(',',$scope);
$permissions = $facebook->api("/me/permissions");
if( array_key_exists('publish_stream', $permissions['data'][0]) && array_key_exists('user_photos', $permissions['data'][0])) {
// the main app logic here
} else {
$user = null;
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
// logged in user
} else {
// not logged in or not authenticated
echo '<script type="text/javascript">top.location.href = "'.$loginUrl .'";</script>';
}
?>
</body>
</html>
和config.php:
<?php
$appName = 'the name';
$appId = '123456789';
$appSecret = '1324v3434v34v';
$baseUrl = 'http://www.domain.com/app-name/';
$appBaseUrl = 'http://apps.facebook.com/zzzzzzz/';
$fbPageURL = 'http://www.facebook.com/xxxxxxx';
$fbPageAppURL = $fbPageURL.'?sk=app_'.$appId;
?>
非常感谢你!!