【问题标题】:How to redirect after authorizing to the canvas page授权后如何重定向到画布页面
【发布时间】: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


【解决方案1】:

看不到您在哪里请求权限,但在安装后将用户重定向到同一个应用程序,我使用以下代码:

$loginUrl   = $facebook->getLoginUrl(
            array(
                'scope'         => 'user_about_me',
                'redirect_uri'  => 'FACEBOOKS_FULL_APP_URL'
            )
    );

【讨论】:

    【解决方案2】:

    正如 cmets 中提到的 moguzalp,这段代码为我完成了它

    <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');
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-21
      • 2019-07-11
      • 1970-01-01
      • 2012-03-20
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      相关资源
      最近更新 更多