becklyn/facebook-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

This bundle provides basic components for the usage with facebook

v1.0.0 2017-11-23 14:19 UTC

This package is auto-updated.

Last update: 2020-02-06 19:11:00 UTC


README

This bundle provides basic components for the usage with facebook.

Facebook App Model

A model which handles a lot of app ("real" app or page tab app) related logic.

Definition

Facebook\Facebook:
    arguments: 
        - app_id: '123456'
          app_secret: 'thisisyoursecret'

Becklyn\FacebookBundle\Model\FacebookAppModel:
    arguments:
        - '@Facebook\Facebook'
        - '@session'
        - '@router'
        - "https://www.facebook.com/Symfony2Framework"          # the fan page url
        - ["email", "user_birthday", "publish_stream"]          # your required permissions
        - "session_identifier"                                  # if you need to use multiple services, you need to define unique session identifiers

This class bundles a lot of the functionality connected to app development with Facebook. It automatically loads the user api data (from a /me request), user request data (from the signed request) and the page data (also from the signed request). Also these values are persistent in the session, so you can safely navigate inside your app iframe without losing all the data.

This data is capsuled in three value objects:

  • Page
    • Bundles the page like, page admin and page id
  • RequestUser
    • Age, country & locale
  • ApiUser
    • Everything from the /me request. Includes direct getters for the most frequent used data (from base permissions + email + user_birthday)

All value objects always contain the complete data as provided by Facebook. You can either use the direct getters or use the getByKey to get data for a value without a direct getter (like if you use more permissions).

Furthermore the App Model provides the following:

  • Direct access to flags, whether the user has liked the page and provided the permissions
  • Getter whether the user is looking at the app in facebook, but not inside your page (like if the user looks at the page as real app and not as page tab, is not persisted between page changes)
  • Page Tab URL generator (including embedding data in app_data)
  • app_data access
  • Wrapper for wall posts

Twig Extensions

Facebook Utilities Twig Extension

Definition

This extension is automatically registered.

Usage

Provides the following Twig functions:

  • {{ fb_likeButton(url, dataAttributes = {}) }} Generates the HTML of a facebook button. You can set all data-attributes in the second argument (omit the data, so provide {href: "..."} for data-href="...")
  • {{ fb_profileImage(facebookId) }} Generates the URL to the profile image for the given facebook id.
  • {{ fb_profileUrl(facebookId) }} Generates the URL to the profile page for the given facebook id.
  • {{ fb_truncateLikeDescriptionText(text, length = 80) }} Truncates the given text and strips all HTML tags from it. The second parameter defines, where the text is truncated ("..." is appended if the text is truncated). The truncation will break words.

Facebook App Twig Extension

Provides twig functions which are related to FacebookAppModel.

Definition

twig.extension.facebook_app:
    class: Becklyn\FacebookBundle\Service\FacebookAppTwigExtension
    tags:
        - { name: twig.extension }
    arguments: [@facebook_app_model]    # definition from above

Usage

Provides the following Twig functions:

  • {{ fb_permissionsData(redirectRoute, redirectRouteParameters = {}) }} Returns an array with two keys: {"hasPermissions": false, "permissionsUrl": "..."}. Can be used json encoded to implement a permissions switch in your app. Expects the redirect route (with parameters) which are needed for the redirect uri used in the generation of the facebook login url.
  • {{ fb_appId() }} Returns the app id as defined in the model.

Additional information

If you use multiple facebook app models, you can automatically prefix these twig functions. The session identifier is used for the prefixing

facebook_app_model_shop:
    class: Becklyn\FacebookBundle\Model\FacebookAppModel
    arguments:
        # ...
        - "shop"        # the session identifier

twig.extension.facebook_app_shop:
    class: Becklyn\FacebookBundle\Service\FacebookAppTwigExtension
    tags:
        - { name: twig.extension }
    arguments: [@facebook_app_model_shop, true]    # The true marks that the functions should be prefixed

The twig functions will now be called:

{{ fb_shop_permissionsData(redirectRoute, redirectRouteParameters = {}) }}
{{ fb_shop_appId() }}

CSS & SCSS

Only one scss file is included, which sets the width and the overflow for an element with the id #fb-wrap, to automatically fit in the app iframe. You can @import it into your own SCSS file.