Facebook未签约

时间:2014-10-30 21:21:38

标签: php facebook facebook-sdk-4.0

我无法登录我的php facebook会话用户。这是我目前的代码:

        public function facebookAction()
    {
        if(isset(Core::session('FacebookAuthSession')->sessionObject)){
//          $oldFetchmode = Core::db()->getFetchMode();
//          Core::db()->setFetchMode(Zend_Db::FETCH_OBJ);
//          $userObj = new Core_Model_User();
//          $facebookUid = Core::session('FacebookAuthSession')->graphObject->backingData['id'];
//          $sel = $userObj->select();
//          $sel->where('fuid=:fuid')->bind(array("fuid"=>$facebookUid));
//          $data = $userObj->fetchRow();
//          $userId = $data->id;
//          Core::db()->setFetchMode($oldFetchmode);
//          Ranger_Application_Util::logUserIn($userId);
            //Core::dump(Core::session('FacebookAuthSession'));
            //die();
            Ranger_Application_Util::redirectToAppUrl('/app/home');
        } else {
            FacebookSession::setDefaultApplication('xxx', 'xxx');
            $helper = new FacebookRedirectLoginHelper('http://jobrangers.com/newhomepage/html/en/auth/facebooklogin');
            $loginUrl = $helper->getLoginUrl();     
            $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper ( 'Redirector' );
            $redirector->gotoUrl ( $loginUrl )->redirectAndExit ();
        }
    }

    public function facebookloginAction()
    {
        FacebookSession::setDefaultApplication('xxx', 'xxx');
        $helper = new FacebookRedirectLoginHelper('http://jobrangers.com/newhomepage/html/en/auth/facebooklogin');
        $session = null;
        try {
            $session = $helper->getSessionFromRedirect();
            Core::session('FacebookAuthSession')->sessionObject = $session;
        } catch(FacebookRequestException $ex) {

        } catch(\Exception $ex) {

        }
        $request = new FacebookRequest($session, 'GET', '/me');
        $response = $request->execute();
        $graphObject = $response->getGraphObject();
        Core::session('FacebookAuthSession')->graphObject = $graphObject;
        $oldFetchmode = Core::db()->getFetchMode();
        Core::db()->setFetchMode(Zend_Db::FETCH_OBJ);
        $userObj = new Core_Model_Resource_Users();
        $backingData = Core::session('FacebookAuthSession')->graphObject->asArray();
        $facebookUid = $backingData['id'];      
        $sel = $userObj->select();
        $sel->where('fuid=:fuid')->bind(array("fuid"=>$facebookUid));
        $data = $userObj->fetchRow();
        Core::db()->setFetchMode($oldFetchmode);
        if($data){
            $userId = $data->id;                            
        } else {
            $data = array();
            $data['date_created'] = new Zend_Db_Expr("NOW()");
            $data['date_updated'] = new Zend_Db_Expr("NOW()");
            $data['fuid'] = $facebookUid;
            $data['first_name'] = $backingData['first_name'];
            $data['last_name'] = $backingData['last_name'];
            $userId = $userObj->insert($data);
        }
        Ranger_Application_Util::logUserIn($userId);
    }

数据保存在Zend_Session_NamespaceCore::session('FacebookAuthSession')

这是我的退出代码:

        public function logoutAction() {        
            $username = Ranger_Application_Util::getStorageData('username');
            Core::log ( "User $username logged out.", Zend_Log::INFO );
            Ranger_Application_Util::makeUserOffline ( Ranger_Application_Util::getStorageData ( 'id' ) );
            Zend_Auth::getInstance ()->clearIdentity ();
            $_SESSION = array();
            Zend_Session::destroy();
            Core::session('FacebookAuthSession')->unsetAll();
            $_COOKIE = array();             
            $locale = Core::registry ( 'Zend_Locale' );
            $this->_redirect ( '/' . $locale->getLanguage ()  );
        }

我尝试删除sessions目录中的所有会话。我还使用Zend_Session::destroy()Core::session('FacebookAuthSession')->unsetAll()来取消设置FacebookAuthSession Namespace中的数据。我不太明白,但它只是回到app home

1 个答案:

答案 0 :(得分:0)

这么简单。我需要退出facebook。