【问题标题】:Facebook like on appliFacebook 喜欢在应用程序上
【发布时间】: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&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 facebook button facebook-like


    【解决方案1】:

    试试这个代码

    <?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
    
    <? } ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-15
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      相关资源
      最近更新 更多