Facebook,登录重装循环

时间:2012-10-15 20:55:41

标签: facebook heroku

我在facebook上运行的facebook应用程序存在一些未知问题

问题现在是访问令牌的问题。我不知道是什么 应用程序中的某些内容似乎会破坏我的访问令牌。因为当我尝试登录到应用程序,然后使用资源管理器时,它表示我已注销或访问令牌已过期。但如果我调试它,它说它有效2个小时。 此外,登录后页面无法重新加载。

显然网站不断重新加载..并一遍又一遍地更新。登录页面时会停止

这个错误似乎最近发生了..上周没有。我猜这个问题会在某处,但我找不到它。 如果您发现任何可能出现问题的内容,请将其提示出来。感谢

require_once('sdk/src/facebook.php');

$facebook = new Facebook(array(
 'appId'  => AppInfo::appID(), 
'secret' => AppInfo::appSecret(), 
'sharedSession' => true,
'trustForwarded' => true,
));

$user_id = $facebook->getUser();
if ($user_id) {
 try {
  // Fetch the viewer's basic information
    $basic = $facebook->api('/me');
 } catch (FacebookApiException $e) {
  // If the call fails we check if we still have a user. The user will be
// cleared if the error is because of an invalid accesstoken
 if (!$facebook->getUser()) {
  header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
  exit();
 }
}

 <script type="text/javascript">
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '<?php echo AppInfo::appID(); ?>', // App ID
      channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true // parse XFBML
    });

   FB.getLoginStatus(function(response) {
    console.log (response.status);
    //this is useful if you want to avoid the infinite loop bug
    //it only reloads page when you log in
    if (response.status != 'connected') {
        FB.Event.subscribe('auth.login', function(response) {
            // We want to reload the page now so PHP can read the cookie that the
            // Javascript SDK sat. But we don't want to use
            // window.location.reload() because if this is in a canvas there was a
            // post made to this page and a reload will trigger a message to the
            // user asking if they want to send data again.
            window.location = window.location;
            //Im using the window.location.reload()
            //window.location.reload();
        });
    }
});
FB.Canvas.setAutoGrow();
 };

  // Load the SDK Asynchronously
  (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/en_US/all.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
</script>
<header class="clearfix">
  <?php if (isset($basic)) { ?>
  <p id="picture" style="background-image: url(https://graph.facebook.com/<?php echo he($user_id); ?>/picture?type=normal)"></p>

  <div>
    <h1>Welcome, <strong><?php echo he(idx($basic, 'name')); ?></strong></h1>
    <p class="tagline">
      This is your new app for sorting events
      <a href="<?php echo he(idx($app_info, 'link'));?>" target="_top"><?php echo he($app_name); ?></a>
    </p>

    <div id="share-app">
      <p>Share this app:</p>
      <ul>
        <li>
          <a href="#" class="facebook-button" id="postToWall" data-url="<?php echo AppInfo::getUrl(); ?>">
            <span class="plus">Post to Wall</span>
          </a>
        </li>
        <li>
          <a href="#" class="facebook-button speech-bubble" id="sendToFriends" data-url="<?php echo AppInfo::getUrl(); ?>">
            <span class="speech-bubble">Send Message</span>
          </a>
        </li>
        <li>
          <a href="#" class="facebook-button apprequests" id="sendRequest" data-message="Prøv den her">
            <span class="apprequests">Send Requests</span>
          </a>
        </li>
      </ul>
    </div>
  </div>
  <?php } else { ?>
  <div>
    <h1>Welcome</h1>
    <div class="fb-login-button" data-scope="user_likes,user_photos,user_events,friends_events, user_hometown,user_location,user_interests,user_about_me,user_education_history,friends_location,read_friendlists"></div> 
  </div>
  <?php } ?>
</header>
<section id="get-started">
 <?php 
 //echo (idx($app_get_events[1], 'id');
 ?>

</section>

1 个答案:

答案 0 :(得分:0)

你正在使用什么浏览器?新的Safari版本不接受来自iframe的cookie。因此,请检查会话是否正常运行,以及是否可以创建cookie。