I'm working on a site which uses the Facebook API to log users in, but I'm having some baffling trouble with the Facebook API itself. I think it's a result of using CodeIgniter.
I added a PHP script that does not use Codeigniter, and it can connect. It looks like this:
require_once("application/libraries/Facebook/facebook.php");
$facebook = new Facebook(array(
'appId' => 'appid-removed-for-question',
'secret' => 'secret-removed-for-question',
));
$user = $facebook->getUser();
echo $user;
This returns the appropriate UID from Facebook.
As soon as I try to do this using a CodeIgniter library, the UID consistently comes back as 0. Here's the library code:
include(APPPATH.'libraries/Facebook/facebook.php');
class Fb_connect extends Facebook{
public $user;
public function __construct()
{
$CI =& get_instance();
$CI->config->load("facebook",TRUE);
$config = $CI->config->item('facebook');
parent::__construct($config);
$this->user = $this->getUser();
echo $this->user;
}
}
I've double and triple-checked my appid and secret in the config file, and even echoed it here to make sure it's coming through as an array correctly, but still nothing. $this->user;
constantly returns 0 for the UID. What am I missing?
I just saw this question which talks about the uri_protocol being the problem, but I had to set $config['uri_protocol'] = 'QUERY_STRING';
to get my mod_rewrite script working in the first place, which makes me wonder if it's the same issue or not. Any advice?
The answer to the question I linked to actually fixed the problem for me:
$config['uri_protocol'] =
(isset($_SERVER['HTTP_REFERER']) &&
strpos($_SERVER['HTTP_REFERER'], 'apps.facebook.com') !== false) ?
"PATH_INFO" : "REQUEST_URI";
use this.. require_once($_SERVER['DOCUMENT_ROOT']."/".$this->config->item('app_folder_path')."application/libraries/Facebook/facebook.php");
Make sure you've set the app_folder_path config variable in your config.php file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.