Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 + Facebook-SDK 4.0 - How to integrate?

If updated now my symfony project to facebook-sdk-v4. My question is now how to integrate it to use in my controllers?

For the old version i had the following line in my autoload.php

//Loading facebook from vendor
require_once __DIR__ . '/../vendor/facebook/php-sdk/src/facebook.php';

then in the controller i could something like that

$facebook = new \Facebook(array(
  'appId'  => $this->container->getParameter('fb_appid'),
  'secret' => $this->container->getParameter('fb_secret')
));
$fb_userid = $facebook->getUser();

without having any use statement in my controller.

Now with version 4.0 its a bit different. There is no facebook.php file anymore in the vendors, therefore i dont know what to require now. And API call differs too, it looks like

FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET');

When i execute that, symfony tells me that it cannot load "FacebookSession" from the global namespace, and if i forget the use statement.

Did anyone have experience how to include the new facebook php sdk in symfony2??

like image 260
Fabian Avatar asked Jul 30 '14 12:07

Fabian


1 Answers

Install the SDK via Composer. Therefore add the following line to the require section of your composer.json and execute composer update afterwards.

"facebook/php-sdk-v4" : "4.0.*"

Facebook SDK will be autoloaded via composer then.

like image 163
sebbo Avatar answered Oct 03 '22 23:10

sebbo