1

使用 facebook connect 访问我开发的网站。

离线一切正常,但在线不正常。我收到导航错误(使用 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%2 +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 时,重定向到登录页面成功,我可以填写电子邮件/密码。

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

4

1 回答 1

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>';
};
于 2012-04-14T17:33:14.863 回答