Facebookページでファンゲートを実装
iframeを使用したFacebookページで「いいね」をクリックしていない人とクリックした人で見せるコンテンツを変える方法です。
まずユーザーが「いいね」を押しているかどうかを判別する以下のコードをparse_signed_request.phpとして外部サーバー(コンテンツページを置くサーバー)にアップします。
<?php 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, '-_', '+/')); } ?>
ウェルカムページ等のxxxx.phpなどではbody直下に以下のような条件分岐を記述して、ファンならばaaa.htmlを表示、そうでないならbbbb.htmlを表示。
<?php include 'parse_signed_request.php'; if (isset($_POST['signed_request'])) { $data = parse_signed_request($_POST['signed_request'], 'xxxxxxxxxxxxx'); } if($data['page']['liked'] == '1'){ include 'aaa.html'; } else { include 'bbb.html'; } ?>
※ xxxxxxxxxxxxx はFacebook開発ページでアプリを作成した際に表示される「アプリの秘訣」キーを入力。
ウェルカムページも下のコンテンツが透けて見えたり、思わせぶりなコピーがあったりと、いろんな見せ方でファンゲートを実装していて発想の参考になります。
No comments yet.