【发布时间】:2012-03-13 01:44:21
【问题描述】:
我正在使用 Php-sdk 上示例中的这段代码,想知道如何在授权后将用户重定向到画布页面,目前它只是发送回 php 页面。
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'AppId',
'secret' => 'Secret',
));
// See if there is a user from a cookie
$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) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$user = null;
}
}
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($user) {
echo " authorized";
?>
Your user profile is
<pre>
<?php print htmlspecialchars(print_r($user_profile, true)); ?>
</pre>
<?php } else { echo "Not Authorized"; ?>
<fb:login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
</html>
简而言之,我该如何设置我的重定向 URL?
【问题讨论】:
-
是的,第一个链接为我做了。唯一的事情,它最后需要一个 而不是答案中的
-
因此,请随时参考链接,甚至更好地添加代码或答案,或者我可以在这方面做些什么。再次感谢。雅及其为我做的第二个链接不是第一个。我看到你已经回答了其他类似的 fb 问题,谢谢。
标签: facebook redirect facebook-apps facebook-authentication