Facebook authentication in function - getUser () returns 0

I am trying to make a function in my controller to post an album on Facebook. Every time a function is available, I am redirected to REDIRECT_URI, as if $ userid = 0, even if I just logged into Facebook correctly. Is it because after logging in, it restarts the function and creates a new Facebook session, destroying the user I just got?

Thanks for any help you can provide.

 function share($id){
            if (!$id) { $this->Session->setFlash(__('Invalid id for Album', true)); 
            $this->redirect(array('action'=>'index')); }  
            $photos = $this->Album->find('all', array('conditions' => array('Album.id' => $id))); 


            $facebook = new Facebook(array('appId'=>'valid aphid', 'secret'=>'valid secret')); 
            $facebook->setFileUploadSupport(true);
            $userid = $facebook->getUser(); 

            if($userid) {               
                try {
                      $user_profile = $facebook->api('/me'); // Gets User information based on permissions the user has granted to your application.

                } 
                catch(FacebookApiException $e){
                    error_log($e);
                    // Print results if you want to debug.
                    $userid = null;
                }

            } else {

                $login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI,'scope' => PERMISSIONS_REQUIRED));
                echo ("<script> top.location.href='".$login_url."'</script>");
            }

            //Create album
            $results = $facebook->api('me/albums', 'post', $photos[0]['Album']['name']);//->photos_createAlbum($albumname, '', '', 'everyone', $this->_userid); 

        }
+5
source share
5 answers

Facebook PHP . :

  • fb_{appid}_user_id: Facebook
  • fb_{appid}_code: ,
  • fb_{appid}_access_token: , API
  • fb_{appid}_state: CSRF

, PHP- .

  • cookie - PHPSESSID; , .
  • , , .
  • ( Facebook). , :

    if (!session_id()) { session_start(); }
    
+4

Facebook, , , 2- . -uri getLoginUrl()! facebook, , 0 ( )

+2
+1

, redirect-uri Facebook getUser(), "" Facebook ( PCheese).

, , loggedin.html, loggedin.php

$facebook = new Facebook(array(
  'appId'  => 'yourAppID',
  'secret' => 'yourSecret',
));

$user = $facebook->getUser();

.

Facebook, , php, http://developers.facebook.com/docs/howtos/login/server-side-login/ ( 6)

0

, , getUser(), 0, Javascript SDK . . , , .

0

All Articles