Ejemplo n.º 1
0
 /**
  * @param string $token
  *
  * @return UserProfileInterface|null
  */
 protected function getTokenInfo($token)
 {
     try {
         // Get the Facebook\GraphNodes\GraphUser object for the current user.
         $response = $this->facebook->get('/me?fields=id,name,email,first_name,last_name', $token);
         $user = $response->getGraphUser();
         // check if we can get user identifier
         if (empty($user->getId())) {
             return null;
         }
         // do not accept tokens generated not for our application even if they are valid,
         // to protect against "man in the middle" attack
         $tokenMetadata = $this->facebook->getOAuth2Client()->debugToken($token);
         // this is not required, but lets be sure because facebook API changes very often
         $tokenMetadata->validateAppId($this->facebook->getApp()->getId());
         $userProfile = new UserProfile();
         $userProfile->setIdentifier($user->getId());
         $userProfile->setDisplayName($user->getName());
         $userProfile->setFirstName($user->getFirstName());
         $userProfile->setLastName($user->getLastName());
         $userProfile->setEmail($user->getEmail());
         // facebook doesn't allow login with not verified email
         if (!empty($user->getEmail())) {
             $userProfile->setEmailVerified(true);
         }
         return $userProfile;
     } catch (FacebookSDKException $e) {
         return null;
     }
 }
 public function indexAction()
 {
     // Initialisation de Facebook
     $fb = new Facebook(['app_id' => $this->getParameter('facebook.app_id'), 'app_secret' => $this->getParameter('facebook.app_secret'), 'default_graph_version' => $this->getParameter('facebook.default_graph_version'), 'default_access_token' => $this->getParameter('facebook.default_access_token')]);
     // Requête sur le nombre de likes
     $request = new FacebookRequest($fb->getApp(), $fb->getDefaultAccessToken(), 'GET', '/RadioGatsun', array('fields' => 'likes'));
     // Extraction
     $likes = $fb->getClient()->sendRequest($request)->getGraphNode()->getField('likes');
     $repository = $this->getDoctrine()->getManager()->getRepository('GatsunWebsiteBundle:Publication');
     $listePublications = $repository->findBy(array(), array('date' => 'desc'), 5, 0);
     $listeVignettes = $this->getDoctrine()->getManager()->getRepository('GatsunWebsiteBundle:Vignette')->findAll();
     $listeEmissions = $this->getDoctrine()->getManager()->getRepository('GatsunWebsiteBundle:Emission')->getNextEmissions(2);
     return $this->render('GatsunWebsiteBundle:General:accueil.html.twig', array('publications' => $listePublications, 'listeVignettes' => $listeVignettes, 'listeEmissions' => $listeEmissions, 'facebookLikes' => $likes));
 }
 /**
  * Perform a Facebook request
  *
  * @param string $action
  *
  * @return \Facebook\FacebookResponse|null
  */
 protected function request($action)
 {
     if ($this->facebook === null) {
         return null;
     }
     try {
         $response = $this->facebook->get($action, $this->facebook->getApp()->getAccessToken());
     } catch (FacebookResponseException $e) {
         \System::log('Facebook response exception: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         return null;
     } catch (FacebookSDKException $e) {
         \System::log('Facebook SDK exception: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         return null;
     }
     return $response;
 }
 public function testPaginationReturnsProperResponse()
 {
     $config = array_merge($this->config, ['http_client_handler' => new FooClientInterface()]);
     $fb = new Facebook($config);
     $request = new FacebookRequest($fb->getApp(), 'foo_token', 'GET');
     $graphEdge = new GraphEdge($request, [], ['paging' => ['cursors' => ['after' => 'bar_after_cursor', 'before' => 'bar_before_cursor']]], '/1337/photos', '\\Facebook\\GraphNodes\\GraphUser');
     $nextPage = $fb->next($graphEdge);
     $this->assertInstanceOf('Facebook\\GraphNodes\\GraphEdge', $nextPage);
     $this->assertInstanceOf('Facebook\\GraphNodes\\GraphUser', $nextPage[0]);
     $this->assertEquals('Foo', $nextPage[0]['name']);
     $lastResponse = $fb->getLastResponse();
     $this->assertInstanceOf('Facebook\\FacebookResponse', $lastResponse);
     $this->assertEquals(1337, $lastResponse->getHttpStatusCode());
 }
Ejemplo n.º 5
0
 /**
  * Init Facebook super-class object with applications settings
  */
 public function init()
 {
     parent::init();
     $this->fb = new \Facebook\Facebook(array('app_id' => $this->app_id, 'app_secret' => $this->app_secret));
     $this->fb->setDefaultAccessToken($this->fb->getApp()->getAccessToken());
 }
Ejemplo n.º 6
0
<?php

use Facebook\Facebook;
use API\src\Config\Config;
use API\src\Server\Session;
require_once __DIR__ . '/../Autoload.php';
$fb = new Facebook(['app_id' => Config::getConfig('FacebookAppId'), 'app_secret' => Config::getConfig('FacebookSecret'), 'default_graph_version' => Config::getConfig('FacebookAPIVersion')]);
$app = $fb->getApp();
$accessToken = $app->getAccessToken();
$accessTokenValue = $accessToken->getValue();
$oauth2 = $fb->getOAuth2Client();
$tokenMeta = $oauth2->debugToken($accessToken);
$tokenMeta->validateAppId(Config::getConfig('FacebookAppId'));
$tokenMeta->validateExpiration();