Wallogit.com
2017 © Pedro Peláez
Faceboo
Integrate Facebook SDK into Silex micro-framework (FacebookServiceProvider) or Symfony2 (FacebooBundle)., (*1)
Provide several methods to do common tasks with Facebook. * authentification * permissions management * fan-gate management, (*2)
Composer, (*3)
modify your composer.json, (*4)
{
"repositories": {
"faceboo": {
"type": "package",
"package": {
"name": "faceboo",
"version": "1.0",
"source": {
"url": "https://github.com/pitpit/Faceboo.git",
"type": "git",
"reference": "master"
}
}
}
},
"require": { ... }
}
Then add to your require section in composer.json following line, (*5)
"require": {
"faceboo": "1.*"
}
$php composer.phar update
Get the sources:, (*6)
cd vendor git clone https://github.com/dpitard/Faceboo.git faceboo cd faceboo git submodule update --init
Register the namespace and the extension, in top of index.php:, (*7)
$app['autoloader']->registerNamespace('Faceboo', __DIR__.'/../vendor/faceboo/src');
$app->register(new Faceboo\Provider\FacebookServiceProvider(), array(
'facebook.app_id' => 'YOUR_APP_ID'
));
The parameters are formated as : facebook.
Login and ask user for permissions if needed:, (*9)
$app['facebook.permissions'] = array();
$app->match('/', function () use ($app) {
if ($response = $app['facebook']->auth()) return $response;
//...
});
In canvas mode, protect your canvas app from direct access to the source server:, (*10)
$app->before(function(Request $request) use ($app) {
if ($response = $app['facebook']->protect()) return $response;
});
* do not rely on it for security, it's based on HTTP_REFERER so it's not safe
In a fan page tab, is the current user admin of the fan page :, (*11)
$app->match('/', function () use ($app) {
$isAdmin = $app['facebook']->isFanPageAdmin();
//...
}
* you need to define "secret" parameter
In a fan page tab, what is the fan page id :, (*12)
$app->match('/', function () use ($app) {
$pageId = $app['facebook']->getFanPageId();
//...
}
* you need to define "secret" parameter
In a fan page tab, does the current user like the fan page :, (*13)
$app->match('/', function () use ($app) {
$isFan = $app['facebook']->isFan();
//...
}
* you need to define "secret" parameter
Get the current facebook user id:, (*14)
$app['facebook']->getUser();
Call the Facebook api:, (*15)
$data = $app['facebook']->api('/me);
Register the autoload in app/autoload.php:, (*16)
$loader->registerNamespaces(array(
//...
'Faceboo' => __DIR__.'/../vendor/faceboo/src'
));
//...
require_once __DIR__.'/../. /vendor/php-sdk/src/facebook.php';
Register the bundle in app/AppKernel.php:, (*17)
$bundles = array(
//...
new Faceboo\FacebookBundle\FacebooFacebookBundle(),
);
Add the following in app/config/config.yml:, (*18)
faceboo_facebook:
app_id: 297720976910223
secret: b151a27351e91dab2ee18986d8c47052
Parameters:, (*19)
Login and ask user for permissions if needed:, (*20)
public function indexAction()
{
if ($response = $this->get('facebook')->auth()) return $response;
//...
}