Facebook Connect脱机工作,但不在线“此网页有重定向循环”

时间:2012-04-14 16:42:51

标签: facebook codeigniter facebook-php-sdk

使用Facebook连接访问我开发的网站。

一切都可以脱机,但不能在线。我收到导航错误(使用Chrome)“此网页有重定向循环”:

https://www.facebook.com/dialog/oauth?client_id=209633612480053&redirect_uri=http%3A%2F%2Fwww.bluward.com%2Faccess%2Flogin_facebook&state=299262ddf89afbf382452df89c9a2ce8&scope=email%2C+user_birthday%2C+user_about_me%2C+user_location%2C+publish_stream&fbconnect=1#= 的网页导致重定向过多。清除此站点的cookie或允许第三方cookie可以解决问题。如果没有,则可能是服务器配置问题,而不是计算机问题。

这是PHP代码(使用CodeIgniter框架):

public function login()
{
  // Get the FB UID of the currently logged in user
  $uid = $fb->getUser();

  // If the user has already allowed the application, you'll be able to get his/her FB UID
  if($uid) {

     try {
        $profile = $fb->api(array(  
            'method'      => 'users.getinfo',  
            'uids'        => $uid,  
            'fields'      => 'uid, first_name, last_name, pic_square, pic_big, sex, birthday_date, current_location, email'
        ));

        // Only the first user.
        $profile = $profile[0];
     } catch (FacebookApiException $e) {
        return false;
     }

     // Do stuff when already logged in.

     return $profile;

  } else {

     // If not, let's redirect to the ALLOW page so we can get access
     redirect($this->getLoginUrl(array(
         'scope'           => 'email, user_birthday, user_about_me, user_location, publish_stream',
         'fbconnect'       =>  1
     )));
  }
}

根据个人资料信息,我检查用户是否已经存在于数据库中,然后记录他/她,如果数据库中不存在,则注册他/她。

更新

当我清除Facebook Cookie时,重定向到登录页面成功,我可以填写电子邮件/密码。

不幸的是,当我点击“登录”按钮时,我收到的错误信息与上面显示的相同。

1 个答案:

答案 0 :(得分:0)

它看起来像你的使用和旧版本?以下是我将如何处理php-sdk 3.1.1“最新版本”的问题。


require 'src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => '135669679827333',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  ));
$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) {
    error_log($e);
    $user = null;
  }
}
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
$params = array(
  scope => 'read_stream,publish_stream,publish_actions,read_friendlists',
  //redirect_uri => $url
  );
  $loginUrl = $facebook->getLoginUrl($params);
  echo '<script> top.location.href=\''.$loginUrl.'\'</script>';
};