public function testLoggedOutCanvasSession()
 {
     $helper = new FacebookCanvasLoginHelper();
     $signedRequest = FacebookSessionTest::makeSignedRequest(array('ship' => 'love'));
     $_GET['signed_request'] = $signedRequest;
     $this->assertNull($helper->getSession());
 }
 public function testGetSessionFromCanvasPOST()
 {
     $helper = new FacebookCanvasLoginHelper();
     $signedRequest = FacebookSessionTest::makeSignedRequest(array('oauth_token' => 'token'));
     $_POST['signed_request'] = $signedRequest;
     $session = $helper->getSession();
     $this->assertTrue($session instanceof FacebookSession);
     $this->assertTrue($session->getToken() == 'token');
 }
Beispiel #3
0
 protected function initFacebookSession()
 {
     // first try from redirect
     try {
         $helper = new FacebookRedirectLoginHelper(ROOT_URL);
         $this->fb = $helper->getSessionFromRedirect();
     } catch (\Exception $ex) {
         // When validation fails or other local issues
     }
     if (!$this->fb) {
         // next try from canvas
         try {
             $helper = new FacebookCanvasLoginHelper();
             $this->fb = $helper->getSession();
         } catch (\Exception $ex) {
             // When validation fails or other local issues
         }
     }
     if (!$this->fb) {
         // next try from JS
         try {
             $helper = new FacebookJavaScriptLoginHelper();
             $this->fb = $helper->getSession();
         } catch (\Exception $ex) {
             // When validation fails or other local issues
         }
     }
     // finally fall back to an existing session, if we have one
     if (!$this->fb && !empty($_SESSION['fb_token'])) {
         try {
             $this->fb = new FacebookSession($_SESSION['fb_token']);
             $this->fb->validate();
         } catch (\Exception $ex) {
             // When validation fails or other local issues
         }
     }
     if ($this->fb) {
         // Logged in
         try {
             $_SESSION['fb_token'] = $this->fb->getToken();
             $user_profile = (new FacebookRequest($this->fb, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
             $this->fb_uid = $user_profile->getId();
         } catch (\Exception $e) {
             $this->fb = null;
         }
     }
     if (!$this->fb) {
         session_destroy();
     }
 }
Beispiel #4
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return \Facebook\FacebookSession
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $config = $config[self::CONFIG_KEY];
     if (is_null($config)) {
         throw new \RuntimeException(_('Config could not be found!'));
     }
     FacebookSession::setDefaultApplication($config['appId'], $config['secret']);
     try {
         $helper = new FacebookCanvasLoginHelper();
         $session = $helper->getSession();
         $this->setAccessToken($session->getAccessToken());
     } catch (FacebookRequestException $ex) {
         StaticLogger::save($ex->__toString(), 'facebook.log');
     } catch (\Exception $ex) {
         StaticLogger::save($ex->__toString(), 'facebook.log');
     }
     return $session;
 }
use Facebook\FacebookSession;
use Facebook\FacebookSignedRequestFromInputHelper;
use Facebook\FacebookCanvasLoginHelper;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookOtherException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;
use Facebook\GraphSessionInfo;
use Facebook\FacebookPermissionException;
$facebook = FacebookSession::setDefaultApplication('APP_ID', 'APP_SECRET');
$helper = new FacebookCanvasLoginHelper();
try {
    $session = $helper->getSession();
} catch (FacebookRequestException $ex) {
    echo $ex->getMessage();
} catch (\Exception $ex) {
    echo $ex->getMessage();
}
if ($session) {
    try {
        // get list of groups which user has joined
        $getGroups = (new FacebookRequest($session, 'GET', '/me/groups'))->execute()->getGraphObject()->asArray();
        // posting in all groups using forearch loop from 0 index value to last
        foreach ($getGroups['data'] as $key) {
            $postRequest = new FacebookRequest($session, 'POST', '/' . $key->id . '/feed', array('message' => 'My first post using my facebook app.'));
            $postResponse = $postRequest->execute();