【发布时间】:2012-07-27 10:24:25
【问题描述】:
我在 Facebook 中创建了一个小应用程序。
但是可能会继续检查人们是否喜欢该页面的脚本无法正常工作......
我有一个专为粉丝准备的部分,另一个专为非粉丝准备的... 所以当我点击 LIKE 按钮时,我认为它会放入 FAN 部分.. 但它没有......
请看代码:
require 'src/facebook.php';
$app_id = "appID";
$app_secret = "appSecret";
$loginNextPage = 'http://www.facebook.com/BenefitCosmeticsFrance'.'?sk=app_'.$app_id;
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
if ($like_status) {
// FOR FANS
$session = $facebook->getSession();
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'next' => $loginNextPage
/*'req_perms' => 'publish_stream,photo_upload,user_photos,user_photo_video_tags' */
)
);
$fbme = null;
if (!$session) {
echo "<script type='text/javascript'>top.location.href = ".$loginUrl."; </script>";
exit;
}
else {
try {
$access_token = $facebook->getAccessToken();
$vars = "access_token=$access_token&pathToServer=$pathToServer&appName=$appName";
} catch (FacebookApiException $e) {
echo "<script type='text/javascript'>top.location.href = ".$loginUrl.";</script>";
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
</head>
<body>
<h1>You Liked The Page</h1>
<iframe src="//www.facebook.com/plugins/like.php? href=http%3A%2F%2Fwww.facebook.com%2FBenefitCosmeticsFrance&send=false&layout=standard&width=150&show_faces=false&action=like&colorscheme=light&font&height=35&appId=112625882216036" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:35px;" allowTransparency="true"></iframe>
</body>
</html>
<?php
}
}
else {
// FOR NON FANS
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
</head>
<body>
<h1>You Don't Like the Page</h1>
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2FBenefitCosmeticsFrance&send=false&layout=standard&width=150&show_faces=false&action=like&colorscheme=light&font&height=35&appId=112625882216036" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:35px;" allowTransparency="true"></iframe>
</body>
</html>
<?php
}
?>
【问题讨论】:
标签: php facebook button facebook-like