【问题标题】:Codeigniter 2.0/Facebook Connect - class init problemCodeigniter 2.0/Facebook Connect - 类初始化问题
【发布时间】:2025-12-20 01:25:10
【问题描述】:

我会继续在所有人面前感到愚蠢,因为我无法发现这里的问题是什么,尽管我怀疑这将是一个真正的呻吟。也许描述它会让我想起一些事情。

我正在根据这个人的工作将 Facebook Connect 与 CI2.0 集成:

http://hitsend.ca/2010/10/facebook-connect-user-authentication-using-the-new-graph-api-in-codeigniter/

我已经升级到 2.0

一些相关的代码位是:

配置/facebook.php:


 $config['facebook_api_key'] = 'xxx';  (it is the ID, not the key, as he misnamed his array key)
 $config['facebook_secret_key'] = 'xxx'; 

控制器/fb_login.php


    function index() {
        $this->load->library('fb_connect');

库/fb_connect.php


    include(APPPATH.'libraries/facebook/facebook.php');

    class fb_connect {
          ....

        function fb_connect()
        {
            //Using the CodeIgniter object, rather than creating a copy of it
            $this->_obj =& get_instance();

            //loading the config paramters for facebook (where we stored our Facebook API and SECRET keys
            $this->_obj->load->config('facebook');
            //make sure the session library is initiated. may have already done this in another method.
            $this->_obj->load->library('session'); 

            $this->_api_key        = $this->_obj->config->item('facebook_api_key');
            $this->_secret_key    = $this->_obj->config->item('facebook_secret_key');

            $this->appkey = $this->_api_key;

            //connect to facebook
            $this->fb = new Facebook(array(
                          'appId'  => $this->_api_key,
                          'secret' => $this->_secret_key,
                          'cookie' => true
                        ));

最后,facebook php 库: 图书馆/facebook/facebook.php


  public function __construct($fb_config) {
print_r($fb_config);
    $this->setAppId($fb_config['appId']);
    $this->setApiSecret($fb_config['secret']);
    if (isset($fb_config['cookie'])) {
      $this->setCookieSupport($fb_config['cookie']);
    }

我能描述这个问题的最好方法就是给你 print_r($fb_config) 的输出:

Array ( [facebook_api_key] => xxx [facebook_secret_key] => xxx) 

和 消息:未定义的索引:appId 消息:未定义的索引:秘密

facebook __construct() 已经加载了配置文件的 $config[] 数组;不知道为什么会这样。

提前感谢任何线索或发现“我做过的愚蠢的事情”

【问题讨论】:

    标签: codeigniter facebook facebook-graph-api


    【解决方案1】:

    数组返回两个键:facebook_api_keyfacebook_secret_key,而构造函数正在尝试读取键 appIdsecret

    另外,您使用的库可能已过时。 The current source (libraries/facebook/facebook.php),第 186-88 行阅读:

    public function __construct($config) {
        $this->setAppId($config['appId']);
        $this->setApiSecret($config['secret']);
    

    【讨论】:

    • 是的,返回错误键的数组是我试图解决的问题。事实证明,较早的设置 Facebook Connect 的尝试仍在开发服务器上,并且正在自动加载一个名为“facebook”的库,该库与我们当前使用的库不同。这种自动加载过早地调用了新库。不清楚为什么它使用配置文件的数组,但我想我必须深入研究核心类才能解决这个问题,而且不太感兴趣
    【解决方案2】:

    是的,返回错误键的数组是我试图解决的问题。事实证明,较早的设置 Facebook Connect 的尝试仍在开发服务器上,并且正在自动加载一个名为“facebook”的库,该库与我们当前使用的库不同。这种自动加载过早地调用了新库。不清楚为什么它使用配置文件的数组,但认为我必须深入研究核心类才能解决这个问题,并且不太感兴趣

    【讨论】: