0

Facebook で小さなアプリケーションを作成しました。

しかし、人々がそのページを気に入っているかどうかをチェックするスクリプトは機能していません...

ファン専用のセクションとファン以外専用のセクションがあります...だから、LIKEボタンをクリックすると、ファンの部分に入れられると思います..しかし、そうではありません...

コードを見てください:

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

}

?>
4

1 に答える 1

0

このコードを試してください

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

<? } ?>
于 2012-07-27T10:54:21.743 に答える