Regards,
I have a problem with Facebook SDK-PHP and Codeigniter.
I do not get the user’s session when I try to capture and obtain basic data for that user.
The error I get is: “An active access token must be used to query information about the current user.”
And when I apply the “getUser ()”, I get “0”.
NOTE: I download the php-sdk and put on my directory libraries the files base_facebook.php and facebook.php
In my application/config/config.php I put the key and app_secret of my facebook application.
Config.php :
$config['base_url'] = 'http://localhost/myapp_local';
$config['app_id'] = 'xxxxxxxxxxxxxx';
$config['secret'] = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$config['app_name'] = 'http://apps.facebook.com/myapp_local/';
In my Controller Main.php i have the follow code:
class Main extends CI_Controller {
public function __construct() {
parent::__construct();
$fb_config = array(
'appId' => $this->config->item('app_id'),
'secret' => $this->config->item('secret')
);
$this->load->library('facebook', $fb_config);
private function _getInfoUserFB() {
try {
$fb_id = $this->facebook->getUser();
if ($fb_id) {
$fb_data = $this->facebook->api('/me');
return $fb_data;
}
} catch (Exception $exc) {
echo $exc;
}
}
[....]
}
Now, in my variables $fb_id , where obtain the bool value, always i have “0”.
So, when i try to get the data of the current user facebook always i have a Exception with the message: “An active access token must be used to query information about the current user.”
$fb_data['id'] = NULL
$fb_data['first_name'] = NULL
$fb_data['last_name'] = NULL
What i doing wrong here? Any step or setting I miss?
NOTE 2: I don’t have some button Login with Facebook, my app connect directly to facebook via the configuration of my app on facebook. (Canvas URL, Secure Canvas URL, Canvas Page, Site URL)
Note 3: My application have some permission that need require, So I put the necessary permissions on Settings-Permissions BUT don’t show me the option of “Auth Referrals” to show Dialog confirm permissions.
I use CodeIgniter version 2.1.3 and PHP-SDK v 3.2.0
You have to go to Facebook Developer Site -> Apps -> Permission. And set the basic info permission for your app.
Then in your function
getLoginUrl(array("scope" => "user_about_me))), you have to give the parameters.Finally you have to save the access token
$this->facebook->getAccessToken();If you have problems you can ask me. I have setup my Codeigniter with nearly all Social Media Platforms 🙂