古いトピックを:)役立つことを願っていますが、私は最近、これを行う方法について多くのことを学びましたし、実際にそれを置くために持っていたようで重量を量るしたかったです。
http://nickring.com/blog/2012/11/facebook-fan-gate-using-php/をご覧ください。他の応答の一部として表示される変数signed_request
を使用しますが、$_REQUEST
を介して変数signed_request
を要求する必要がない方法を示しています。
signed_request
は、signed_request
にアクセスするPHPスクリプトがFacebook内で実行されている場合にのみ利用可能です。 Facebook APIを使用しようとしているスクリプトでFacebook外でこのスクリプトを実行すると、空の配列が返されます。
この例では、このアドレスに行くと次のスクリプトが実行されます:https://www.facebook.com/yourFacebookPage/app_xxxxxxxxxxxxxxx「xxxxxxxxxxxxxxx」がアプリIDです。
// Check if the user has liked us on Facebook, require the Facebook SDK
require_once('linked/facebook/facebook.php');
// Setup the Config
$config = array(
'appId' => 'xxxxxxxxxxxxxxxxx',
'secret' => 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
'cookie' => true
);
// Create a Facebook SDK instance
$facebook = new Facebook($config);
// Get the signed_request variable that we so desparately need
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
// Make sure that it worked
if (!empty($signed_request))
{
// Get the signed_request information
if ($like_status == 1)
{
// Wo0t! Show the FB fan only page stuff here
}
else
{
// Show the 'Please like us page'
$page = file_get_contents('pages/facebookLikeUs.html');
// Finish the page
echo $page;
exit();
} // End if ($like_status == 1) ELSE Clause and IF
} // End if (!empty($signed_request)) IF Clause
else
{
// Damn, it didn't work. Show an error
}
上記のスクリプトは、アプリの設定の「アプリケーションのFacebook上の」セクションのキャンバスURLに設定されたURLから呼び出されるスクリプトです。 facebookLikeUs.html
ページは、単に「好き」をクリックして続行するように要求するページです。
:
facebookRedirectBack.html
ページが、このことで
// Wo0t! They're all set, establish some cookies, get a cookie, and redirect back to the PHD program site
setcookie('fbls', $signed_request['page']['id'] . '-' . $signed_request['user_id'], time() + 300);
$redirectURL = "http://www.myurl.com/theScriptIWantToReceiveTheUserFromFB.php";
// Since Facebook really wants to keep us in the page, we need to create a page that will automatically break out of FB
$page = file_get_contents('pages/facebookRedirectBack.html');
// Replace some stuff
$page = str_replace('$redirectURL', $redirectURL, $page);
// Output the page
echo $page;
exit();
:私は、私は彼らが戻って私は単にこのような何かを持つ// Wo0t!
部分を置き換えるようにFacebookのを必要とし、ウェブサイトにリダイレクトするような状況にいる場合
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
window.top.location.href = '$redirectURL';
</script>
</body>
</html>
セキュリティを少し強化したい場合は、リダイレクトするPHPスクリプトにいくつかのCookieを書き込んで、URLに添付して、受信スクリプトがCookieとURLパラメータを比較して削除する必要があります彼らが読んだ後のクッキー。
私は個人的にこの件に関する一貫した情報を見つけられていないので、これが役に立ちます。
あなたが言及しているのは「類似ゲート」と呼ばれています。この前の質問をチェックしてください:http://stackoverflow.com/questions/5329818/seamless-way-to-check-if-user-likes-page – Lix