public function testMeReturnsGraphUser()
 {
     $response = (new FacebookRequest(FacebookTestHelper::$testSession, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
     $info = FacebookTestHelper::$testSession->getSessionInfo();
     $this->assertTrue($response instanceof GraphUser);
     $this->assertEquals($info->getId(), $response->getId());
     $this->assertNotNull($response->getName());
     $this->assertNotNull($response->getLastName());
     $this->assertNotNull($response->getLink());
 }
 public function testAsList()
 {
     $backingData = array('data' => array(array('id' => 1, 'name' => 'David'), array('id' => 2, 'name' => 'Fosco')));
     $enc = json_encode($backingData);
     $response = new FacebookResponse(null, json_decode($enc), $enc);
     $list = $response->getGraphObjectList(GraphUser::className());
     $this->assertEquals(2, count($list));
     $this->assertTrue($list[0] instanceof GraphObject);
     $this->assertTrue($list[1] instanceof GraphObject);
     $this->assertEquals('David', $list[0]->getName());
     $this->assertEquals('Fosco', $list[1]->getName());
 }
Esempio n. 3
0
 public function getUser($userId = 'me')
 {
     try {
         $request = new FacebookRequest($this->getSession(), 'GET', '/' . $userId);
         return $request->execute()->getGraphObject(GraphUser::className())->asArray();
     } catch (Exception $e) {
     }
     return [];
 }
Esempio n. 4
0
session_start();
require 'config/facebook.php';
require 'vendor/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\GraphUser;
use Facebook\GraphObject;
use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication($config['app_id'], $config['app_secret']);
$helper = new FacebookRedirectLoginHelper('http://localhost/subastaloDotCom/home/');
try {
    $session = $helper->getSessionFromRedirect();
    if ($session) {
        $_SESSION['facebook'] = $session->getToken();
        header('Location: index.php');
    }
    if (isset($_SESSION['facebook'])) {
        $session = new FacebookSession($_SESSION['facebook']);
        $request = new FacebookRequest($session, 'GET', '/me');
        $response = $request->execute();
        $graphObjectClass = $response->getGraphObject(\Facebook\GraphNodes\GraphUser::className());
        $facebook_User = $graphObjectClass;
    }
} catch (FacebookRequestException $ex) {
    // When Facebook returns an error
} catch (\Exception $ex) {
    // When validation fails or other local issues
}