授权后如何重定向到canvas页面
我正在 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?
I am using this code from the example on Php-sdk , wondering how do I redirect the user to the canvas page after authorizing, currently it just sends back to the php page.
<?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>
So in short, how do I set my redirect URL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法看到您在哪里请求权限,但为了在安装后将用户重定向到同一个应用程序,我使用了以下代码:
Can't see where you are asking for permissions, but to redirect users to the same app after installing i use this code:
正如 moguzalp 在评论中提到的那样,这段代码为我完成了
我刚刚在下面添加的代码
As moguzalp referred in the comments, this bit of code did it for me
I just added this under