ユーザーがいいねボタンをクリックしたときに、ユーザーを別のページにリダイレクトすることはできません。ここで質問する前に検索しました。これに関するいくつかのトピックを見つけましたが、まだうまくいきません...
これは私のコードです: ご協力ありがとうございます!
<?php
require 'php-sdk/src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '453976824647366',
'secret' => 'XXXXXX',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
// try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
// } catch (FacebookApiException $e) {
// error_log($e);
// $user = null;
// }
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<style>
body {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
}
h1 a {
text-decoration: none;
color: #3b5998;
}
h1 a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<div>
<a href="<?php echo $loginUrl; ?>">Login</a>
</div>
<?php endif ?>
<?php if ($user): ?>
<h3>Vous</h3>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
<h3>Personne connectée</h3>
<!-- <pre><?php print_r($user_profile); ?></pre>-->
<?php
echo $user_profile['first_name'];
echo '<a href="' . $user_profile['link'] . '">Go to my profile</a>';
?>
<?php else: ?>
<strong><em>Vous n'êtes pas connecté</em></strong>
<?php endif ?>
<div class="fb-like" data-href="http://apps.facebook.com/453976824647366/" data-width="450" data-show-faces="true"></div>
</body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/fr_FR/all.js#xfbml=1&appId=453976824647366";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function() {
FB.init({appId: '453976824647366', status: true, cookie: true, xfbml: true});
FB.Canvas.setSize({ width: 520, height: 1500 });
FB.Event.subscribe('edge.create',
function(response) {
alert('like!');
// put redirect code here eg
window.location = "index2.php";
location.href = 'index2.php';
}
);
};
</script>
</html>