如何在授权画布页面后进行重定向 [英] How to redirect after authorizing to the canvas page

查看:190
本文介绍了如何在授权画布页面后进行重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Php-sdk中的示例中的代码,想知道如何在授权后将用户重定向到画布页面,目前它只是发回到php页面。

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?

推荐答案

由于moguzalp在评论中提到,这一段代码为我做了一个

As moguzalp referred in the comments, this bit of code did it for me

<script type='text/javascript'>
if (window.top.location == window.location) 
window.top.location = 'https://apps.facebook.com/myapp';
</script>

我刚刚添加了

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  }

这篇关于如何在授权画布页面后进行重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆