0

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.

Dail
  • 4,622
  • 16
  • 74
  • 109
  • `getUser` will return `0` if the user hasn't authenticated your application... Have you sent your users to the login screen for your app? – Lix Jul 15 '12 at 08:10
  • @Lix sure, I have sent the user to the login Page... as you can see I passed the scope and the redirect_uri. The strange thing is that, Facebook calls my redirect_uri without problem (I do not see error parameter in the querystring). And then, it is strange because i'm doing this test with my account.... I already registered to this app :/ – Dail Jul 15 '12 at 08:13
  • @Lix too strange, take a look at my EDIT – Dail Jul 15 '12 at 09:31

0 Answers0