I have develop a simple method of my class that does the Facebook login, this is the code:
public function auth()
{
$config = array(
'appId' => Configure::read('FB.id'),
'secret' => Configure::read('FB.secret'),
'cookie' => true
);
$this->provider = new Facebook($config);
$user = $this->provider->getUser();
debug($user);
debug($_GET['code']);
if ($user)
{
return $user;
}
// Errors?
if (!isset($this->controller->request->query['error']))
{
$params = array(
'scope' => Configure::read('FB.scope'),
'redirect_uri' => Configure::read('FB.callback')
);
// Redirect login page
$this->controller->Session->write('login.redirect', $this->provider->getLoginUrl($params));
}
return false;
}
The method is simple, i have followed the Facebook SDK examples.
I have a problem retrieving information of the user, because when Facebook calls my redirect_uri, I get the follow parameters (querystring)
- state
- code
So, I do not get any error from Facebook.....but getUser() still returns 0.
Why?
##### EDIT: #####
It is really too strange... it only works if I change the redirect uri with the facebook app uri, I changed:
https://www.mywebsite.com/panel/
with
https://apps.facebook.com/MY_APP/panel/
and it works.... hmmm, why do I have to use Facebook URL ?
P.S. I'm using CakePhp, I know there are plugins that do this Job for me, but I also started with CakePhp, so I would learn the code writing it.