我想创建一个 PHP 脚本来检查用户是否喜欢该页面。如果用户喜欢该页面,他将被重定向到另一个 URL,如果不是,则要求用户喜欢该页面,并且出现 facebook 喜欢按钮,以便用户可以喜欢。
请问这怎么做?我设法掌握了这个脚本并得到了错误。请问有什么帮助吗?
谢谢
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Facebook "If-Like" Application | ThreeDots</title>
</head>
<body>
<?php
include_once( "facebook.php" );
$fbAppArray = array(
'appId' => 'YOUR_APPLICATION_ID',
'secert' => 'YOUR_APPLICATION_SECRET',
'cookie' => true
);
$fbAppObj = new Facebook( $fbAppArray );
$signedRequest = $fbAppObj->getSignedRequest();
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;
}
if( $signedRequest = parsePageSignedRequest() )
{
if( $signedRequest->page->liked )
{
// What to show the user if he liked the application...
}else{
// Please like the application so you will be able to see the contents...
}
}
?>
</body>
</html>