2017 © Pedro Peláez
 

library faceboo

Faceboo

image

emgiezet/faceboo

Faceboo

  • Monday, October 1, 2012
  • by emgiezet
  • Repository
  • 1 Watchers
  • 0 Stars
  • 89 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

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)

Installation

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.*"
    }
    
  • Finally update your composer: $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

Parameters

  • app_id: you app id
  • secret: your app secret
  • permissions: array of facebook permissions needed to access the app
    • http://developers.facebook.com/docs/reference/api/permissions/
  • namespace: your app namespace
  • canvas: true if your app work under a facebook iframe
  • proxy: to make facebook requests work behind non-transparent proxy
  • timeout :
  • connect_timeout
  • protect: true|false, disable the redirection when accessing the server, in canvas mode
  • class_path (silex only): define another path to reach Facebook PHP SDK

Usage

Silex

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., (*8)

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);

Symfony2

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)

  • facebook.app_id: you app id
  • facebook.secret: your app secret
  • facebook.permissions: array of facebook permissions needed to access the app
    • http://developers.facebook.com/docs/reference/api/permissions/
  • facebook.namespace: your app namespace
  • facebook.canvas: true if your app work under a facebook iframe
  • facebook.proxy: to make facebook requests work behind non-transparent proxy
  • facebook.timeout
  • facebook.connect_timeout
  • facebook.protect: true|false, disable the redirection when accessing the server, in canvas mode
  • facebook.class_path: define another path to reach Facebook PHP SDK

Login and ask user for permissions if needed:, (*20)

public function indexAction()
{   
    if ($response = $this->get('facebook')->auth()) return $response;

    //...
}

Todo

  • developp permissions authorization on website mode
  • get rid of SilexEvent dependency to make it work with Symfony
  • In canvas mode, override UrlGenerator to have the canvas URL when generate() is called with $absolute = true
  • fan page
    • does the user like the fan page ?
    • route according to local

Changelog

  • added symfony support
  • app_id and secret are now mandatory
  • updated to last version of Silex
  • updated parameter prefix (now "facebook")

The Versions

01/10 2012

dev-master

9999999-dev

Faceboo

  Sources   Download

MIT

The Requires

  • php >=5.3.0