7

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??

Fabian
  • 1,806
  • 5
  • 25
  • 40

1 Answers1

8

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.

sebbo
  • 2,929
  • 2
  • 20
  • 37
  • 1
    Once you do this, how do you access the classes from within your own Bundle? Do you need a 'Use' statement, and if so what is it? – Craig Nakamoto Oct 30 '14 at 20:19
  • 1
    use \Facebook; then you can use it like $f = new Facebook(...); – Erhard Dinhobl Dec 29 '14 at 16:52
  • while it is not the same package but it is the same none namespace issue integration to symfony2 solution here: http://stackoverflow.com/questions/13588791/symfony2-integrating-with-a-non-namespaced-sdk-paypal-specifically/34847963#34847963 – Dung Jan 18 '16 at 05:47
  • To avoid fiddling in composer.json, you could use this: `composer require facebook/php-sdk-v4:4.0.*` It is then automatically installed :) – ar34z Feb 08 '16 at 15:06