Facebook-Ignited(facebook php-sdk) - 无限循环/如何调试?

时间:2011-06-22 08:15:50

标签: php facebook codeigniter

我使用facebook-ignited包时遇到问题。

网络服务器: MAMP + OSX 10.6.7 / PHP:5.2.13 (通过“本地域”访问[etc / hosts - local.mydomain.de,MAMP / apache中的虚拟主机])

Codeigniter Reactor:2.0.2 CIBonfire:1.0.1 Facebook点燃:1.0.4

配置/ fb_ignited.php:

$config['fb_appid']        = 'XXXXXX6';
$config['fb_secret']    = 'XXXXXX';
$config['fb_cookie']    = true;
$config['fb_canvas']    = '';
$config['fb_auth']        = '';[/code]

控制器:

 class welcomeFacebook extends Front_Controller{
     function getMe(){
         // The fb_ignited library is already auto-loaded so call the user and app.
         $this->load->library('fb_ignited');
         $this->fb_me = $this->fb_ignited->fb_get_me(false);    

         if (isset($this->request_result)){
             $content_data['error'] = $this->request_result;
         }

         $content_data['me'] = $this->fb_me;
         $content_data['fb_app'] = $this->fb_app;
         $this->load->view('welcome_message_fbignited', $content_data); // the default facebook_ignited view template

    }
}

结果是使用Chrome和Safari的无限循环,无论是否已经登录facebook ...

oauth (www.facebook/com/dialog) 302 Found
uiserver.php (www.facebook.com/connect) 302 Found
/welcomeFacebook/getMe/?code=[….]&state=[….]
oauth (www.facebook/com/dialog) 302 Found
...

fb_get_me()(Fb_ignited)永久失败,因为$ this-> CI-> facebook-> getUser()不会返回用户,因此会一遍又一遍地重定向。我发现,没有签名的请求。并且getUserFromAvailableData()(base_facebook.php)无法获取用户数据。

app-id和app_secret很好,因为我用javascript-sdk进行了测试,一切运行良好。

我该怎么调试呢?是否有php-sdk / facebook-ignited的调试选项? 或者它是codeigniter-cookie / session相关的问题? (或者是别的什么?;))

提前感谢您的帮助!

的Matthias

PS:3380417没有帮助。

2 个答案:

答案 0 :(得分:3)

问题是由于htaccess的干净网址(没有index.php)引起的:

RewriteRule ^(.*)$ /index.php?/$1 [L]

我现在有2个解决方案:

config.php - 启用查询字符串

| Please note that some of the helpers won't work as expected when
| this feature is enabled, since CodeIgniter is designed primarily to
| use segment based URLs.
$config['enable_query_strings'] = TRUE; 

或者,如果您不想将其全局启用,请将其粘贴到构造函数或方法中:

parse_str($_SERVER['QUERY_STRING'],$getArr);
$_REQUEST['state']=$getArr['state'];
$_REQUEST['code']=$getArr['code']; 

我不知道这是否会导致一些安全问题......

答案 1 :(得分:0)

我使用的是CodeIgniter 2.2.0和Facebook PHP SDK 3.2.3。

Programmieraffe提出的第一个解决方案并不适用于我,因为我依赖许多需要CI干净URL的库。

然而,第二个是通过简单地以这种方式修补BaseFacebook类的构造函数来工作的:

public function __construct($config) {

// patched to work with CodeIgniter's clean URLs
parse_str($_SERVER['QUERY_STRING'],$request);
$_REQUEST = $request;

$this->setAppId($config['appId']);
$this->setAppSecret($config['secret']);
if (isset($config['fileUpload'])) {
  $this->setFileUploadSupport($config['fileUpload']);
}
if (isset($config['trustForwarded']) && $config['trustForwarded']) {
  $this->trustForwarded = true;
}
if (isset($config['allowSignedRequest'])
    && !$config['allowSignedRequest']) {
    $this->allowSignedRequest = false;
}
$state = $this->getPersistentData('state');
if (!empty($state)) {
  $this->state = $state;
}

}

由于Facebook SDK期望从查询字符串中读取已签名的请求,并且CodeIgniter禁用它,因此完全读取它并覆盖整个$ _REQUEST变量将完成此任务。 这样,SDK仍将从$ _REQUEST读取,而不会注意到CI执行的任何操作。

希望有所帮助:)