简体   繁体   English

Symfony2 + Facebook-SDK 4.0 - 如何集成?

[英]Symfony2 + Facebook-SDK 4.0 - How to integrate?

If updated now my symfony project to facebook-sdk-v4. 如果现在更新我的symfony项目到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 对于旧版本,我在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. 现在4.0版本有点不同了。 There is no facebook.php file anymore in the vendors, therefore i dont know what to require now. 供应商中不再有facebook.php文件,因此我现在不知道需要什么。 And API call differs too, it looks like 和API调用也不同,它看起来像

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. 当我执行它时,symfony告诉我它无法从全局命名空间加载“FacebookSession”,如果我忘记了use语句。

Did anyone have experience how to include the new facebook php sdk in symfony2?? 有没有人有经验如何在symfony2中包含新的facebook php sdk?

Install the SDK via Composer. 通过Composer安装SDK。 Therefore add the following line to the require section of your composer.json and execute composer update afterwards. 因此,将以下行添加到composer.json的require部分,然后执行composer update

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

Facebook SDK will be autoloaded via composer then. Facebook SDK将通过composer自动加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM