3
votes

I'm beginner in cakephp and I'm trying to use the Facebook php sdk but i get conflict between cakephp auth login function and facebook sdk calling

$facebook = new Facebook(array(
    'appId'  => '123456789',
    'secret' => 'abcdefghijklmnopqrstuvwxyz',
    'cookie' => true
));
$fbuserid = $facebook->getUser();
if ($fbuserid) {
    try {
        $Uinfo = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $fbuserid = null;
    }
}
// some code here
$this->Auth->login($userdata);

this code works perfectly only if i removing facebook class calling

2
Try to describe your problem better. "I get a conflict" isn't very helpful. Also where does $userdata come from. - ori
I developed a few fb apps with cakephp, and in my experience it's sometimes easier to drop Auth and just check $facebook->getUser() in AppController. - ori
Thanks for replies, i cut the facebook calling code from function, and put it in beforefilter() function, this work fine - Mostafa
Hey thanks Mostafa, that worked for me :) I was also facing the same issue. After moving the Facebook object creation code to the AppControllers Beforefiler it start working fine. - Vijay Kumbhar
This one worked for me. What is the issue with Facebook SDK and CakePHP's Auth? - Teej

2 Answers

1
votes

There is a lot going on in the Facebook SDK. There is a great plugin written for CakePHP by WebTechNick over on GitHub. Maybe this will help you so you are not reinventing the wheel. Check it out here:

https://github.com/webtechnick/CakePHP-Facebook-Plugin