Codeigniter 2.0/Facebook Connect - 类初始化问题
我会继续在每个人面前感到愚蠢,因为我无法发现这里的问题是什么,尽管我怀疑这将是一个真正的呻吟。也许描述它会让我想起一些东西。
我正在根据这个人的工作进行 Facebook Connect 与 CI2.0 的集成:
我已经升级到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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该数组返回两个键:
facebook_api_key
和facebook_secret_key
,而构造函数正在尝试读取键appId
和secret
另外,您使用的库可能已过时。 当前来源< /a> (
libraries/facebook/facebook.php
),第 186-88 行如下:The array returns two keys:
facebook_api_key
andfacebook_secret_key
, while the constructor is trying to read keysappId
andsecret
Also, the library you're using might be out of date. The current source (
libraries/facebook/facebook.php
), lines 186-88 read:是的,返回错误键的数组正是我试图解决的问题。事实证明,早期设置 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