Codeigniter 2.0/Facebook Connect - 类初始化问题

发布于 2024-11-04 19:30:58 字数 2555 浏览 0 评论 0原文

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

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

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

我已经升级到2.0

一些相关的代码位是:

config/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'; 

controllers/fb_login.phplibraries


    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库: Library/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[] 数组;不知道为什么要这样做。

预先感谢您提供任何有关“我做过的愚蠢事情”的线索或发现

I'll go ahead and feel silly in front of everyone, cuz I can't spot what the issue here is, though I suspect it will be a real groaner. maybe describing it will jog something in my mind.

i am doing a Facebook Connect integration with CI2.0, based on this guy's work:

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

which I've upgraded to 2.0

some relevant code bits are:

config/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'; 

controllers/fb_login.php


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

libraries/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
                        ));

and finally, the facebook php library:
libraries/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']);
    }

The best way I can describe the issue is just to give you the output of print_r($fb_config):

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

and
Message: Undefined index: appId
Message: Undefined index: secret

The facebook __construct() has been loading with the config file's $config[] array; no idea why it is doing this.

Thanks in advance for any leads or spottings of "dumb things I've done"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兮子 2024-11-11 19:30:58

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

另外,您使用的库可能已过时。 当前来源< /a> (libraries/facebook/facebook.php),第 186-88 行如下:

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

The array returns two keys: facebook_api_key and facebook_secret_key, while the constructor is trying to read keys appId and secret

Also, the library you're using might be out of date. The current source (libraries/facebook/facebook.php), lines 186-88 read:

public function __construct($config) {
    $this->setAppId($config['appId']);
    $this->setApiSecret($config['secret']);
复古式 2024-11-11 19:30:58

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

yes, the array returning the wrong keys was what i was trying to work out. turns out, an earlier attempt to set up Facebook Connect was still on the dev server, and was auto-loading a library called "facebook" which was not the same as the current one we are using. this autoloading was calling the new library too early. not clear why it was using the config file's array, but think I would have to dig through the core classes to work that out, and not so interested

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文