Facebook扇门与PHP sdk V4

时间:2014-05-20 09:16:32

标签: php facebook facebook-graph-api facebook-php-sdk

我正在尝试过去两天让我的演示应用程序请求在转到“竞赛”之前。 这是一种非常基本的方法。 使用新的Php Facebook Sdk V4,我看不出我如何检查用户是否喜欢我的页面继续。

Old Api

$signed_request = $facebook->getSignedRequest();
if(!$signed_request['page']['liked']){
echo '<h1>Like us!</h1>
         like our Page:  <div class="fb-like" data-href="http://www.facebook.com/pages/xxxx" data-send="false" data-width="450" data-show-faces="true"></div>
           Like our app!!!<iframe src="http://www.facebook.com/plugins/like.php?app_id=xxxx&amp;href=http%3A%2F%2Fwww.xxxx.com%2Ffbapp%3Fv%3D3&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>';
           exit();
}else{
echo '<h1>Thank you!!!!!</h1>';
}
$loginUrl   = $facebook->getLoginUrl(
        array('scope'  => 'publish_stream') );

1 个答案:

答案 0 :(得分:1)

我用这个:

function parsePageSignedRequest()
{
  if (isset($_REQUEST['signed_request'])) {
    $encoded_sig = null; $payload = null;
    list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
    $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
    return $data;
  }
  return false;
}

$signed_request = parsePageSignedRequest();

if ($signed_request->page->liked) {
    // content for fans 
<?php } else { ?>
    // content for non-fans
<?php } ?>