脸书喜欢应用程序



我在Facebook中创建了一个小应用程序。

但是,可以继续检查页面是否为People LIKE的脚本不起作用。。。

我有一个部分只为粉丝,另一个部分仅为非粉丝。。。所以当我点击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&amp;send=false&amp;layout=standard&amp;width=150&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35&amp;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&amp;send=false&amp;layout=standard&amp;width=150&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35&amp;appId=112625882216036" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:35px;" allowTransparency="true"></iframe>
</body>
</html>
<?php
}
?>

尝试此代码

<?php
require 'facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'YOUR APP ID',
  'secret' => 'YOUR APP SECRET',
  'cookie' => true,
));


$session = $facebook->getSession();
$me = null;
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}

$signed_request = $_REQUEST["signed_request"];

function parse_signed_request($signed_request, $secret) {
  list($encoded_sig, $payload) = explode('.', $signed_request, 2);
  // decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);
  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    error_log('Unknown algorithm. Expected HMAC-SHA256');
    return null;
  }
  // check sig
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if ($sig !== $expected_sig) {
    error_log('Bad Signed JSON signature!');
    return null;
  }
  return $data;
}
function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}
$data = parse_signed_request($_REQUEST["signed_request"], "YOUR APP SECRET");

?>


<? if ($data['page']['liked']){ ?>
//FOR FANS
<? }else{ ?>
//FOR NON FANS
<? } ?>

相关内容

最新更新