2017 © Pedro PelĂĄez
 

library facebook-service-provider

Lightweight silex service to ease communication with facebook

image

insolis/facebook-service-provider

Lightweight silex service to ease communication with facebook

  • Thursday, March 20, 2014
  • by maerlyn
  • Repository
  • 2 Watchers
  • 0 Stars
  • 253 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

facebook-service-provider

It's a lightweight Silex service to help creating Facebook applications., (*1)

Dependencies

It depends on two other providers:, (*2)

It also uses the current request., (*3)

Configuration

It's done via the fb.options key. It's supposed to be an array with the following keys:, (*4)

  • app_id: your application's id
  • app_secret: your application's secret token
  • permissions: an array with the needed permissions
  • redirect_route: name of the route which is responsible for handling new user authentications

Usage

The service sets the following session keys:, (*5)

  • fb.access_token: the access token you can use to make requests against the graph API
  • fb.page_liked: whether the current page is liked or not

A before() middleware is registered to be run before yours. It handles two cases:, (*6)

  • it's a post request and we have a signed_request parameter: decoding is done automatically and set among the post values with the fb.data key
  • it's a request for the aforementioned redirect route, and we have a code query parameter: fetching a token, then the user details is done automatically, set among the post values with the fb.data key

In both cases the event fb.user_info is dispatched, with the user data as the subject., (*7)

Events

  • fb.user_info when getting user data from facebook
  • fb.like when the user just liked the page
  • fb.unlike when the user just unliked the page

Samples

A sample application-level before middleware to log a user in automatically:, (*8)

<?php

$app->before(function (Request $request) use ($app) {
    if ($request->request->has("fbdata")) {
        $data = $request->request->get("fbdata");

        if (isset($data["user_id"])) {
            $app["session"]->set("user_id", $data["user_id"]);
        }
    }

    $route = $request->get("_route");
    if (
        !$app["session"]->has("user_id") &&
        !in_array($request->get("_route"), array("homepage", "fb_addhandler"))
    ) {
        return new Response("<script type='text/javascript'>top.location = '" . $app["fb"]->getAuthorizationUrl() . "';</script>");
    }
});

A sample redirect route to handle new user authentications:, (*9)

<?php

$app->post("/fb_addhandler", function (Request $request) use ($app) {
    if (!$request->request->has("fbdata")) {
        return $app->redirect($app["url_generator"]->generate("homepage"));
    }

    $data = $request->request->get("fbdata");

    try {
        $app["db.user"]->insert(array(
            "id"    =>  $data["id"],
        ));
    }
    catch (\Exception $e) {
        //this is not the user's first time enabling the app
    }

    $app["session"]->set("user_id", $data["id"]);

    return $app->redirect($app["url_generator"]->generate("homepage"));
})->bind("fb_addhandler");

The Versions

20/03 2014

dev-master

9999999-dev

Lightweight silex service to ease communication with facebook

  Sources   Download

MIT

The Requires

 

20/03 2014

v1.3

1.3.0.0

Lightweight silex service to ease communication with facebook

  Sources   Download

MIT

The Requires

 

18/03 2014

v1.2.2

1.2.2.0

Lightweight silex service to ease communication with facebook

  Sources   Download

MIT

The Requires

 

12/03 2014

v1.2.1

1.2.1.0

Lightweight silex service to ease communication with facebook

  Sources   Download

MIT

The Requires

 

10/03 2014

v1.2

1.2.0.0

Lightweight silex service to ease communication with facebook

  Sources   Download

MIT

The Requires

 

02/10 2013

v1.1

1.1.0.0

Lightweight silex service to ease communication with facebook

  Sources   Download

MIT

The Requires

 

27/08 2013

v1.0

1.0.0.0

Lightweight silex service to ease communication with facebook

  Sources   Download

MIT

The Requires