PHPackages                             splashlab/yii-facebook-opengraph - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. splashlab/yii-facebook-opengraph

ActiveLibrary[API Development](/categories/api)

splashlab/yii-facebook-opengraph
================================

Yii1 Extension for the Facebook Open Graph 2.x and PHP SDK 5.x

1.0.2-beta(11y ago)4346.5k↓22.2%12GNU Lesser General Public License v3.0PHPPHP &gt;=5.4

Since Jan 15Pushed 10y ago15 watchersCompare

[ Source](https://github.com/splashlab/yii-facebook-opengraph)[ Packagist](https://packagist.org/packages/splashlab/yii-facebook-opengraph)[ Docs](https://github.com/splashlab/yii-facebook-opengraph)[ RSS](/packages/splashlab-yii-facebook-opengraph/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

The master branch is not stable, please use tagged release branches. The previous stable branch with support for the old API is now under the `opengraph-v1.0` branch.

#### This is a Yii1 application component wrapper for Facebook PHP SDK 5.0

[](#this-is-a-yii1-application-component-wrapper-for-facebook-php-sdk-50)

Also included are some helper functions that:

- Include the Facebook JS SDK on your pages
- Allow setting Open Graph meta tags
- Easy rendering of Facebook Social Plugins.

Facebook PHP SDK:

-
-
-

Facebook JS SDK:

-

Facebook Social Plugins:

-

Open Graph Protocol:

-

Upgrading from PHP SDK 4 to PHP SDK 5

-

---

INSTALLATION:
-------------

[](#installation)

It is recommended that you install this via composer. This extension is hosted on packagist.org:

```
"require": {
    "splashlab/yii-facebook-opengraph": "dev-master"
}

```

Instead of 'dev-master' you can choose a release tag like '1.0.2-beta'.

Run `composer update` to get the extension. This will pull down the official Facebook SDK as a dependency.

Configure Yii application component SFacebook in your yii config file:

```
'components'=>[
    'facebook'=>[
        'class' => '\YiiFacebook\SFacebook',
        'appId'=>'YOUR_FACEBOOK_APP_ID', // needed for JS SDK, Social Plugins and PHP SDK
        'secret'=>'YOUR_FACEBOOK_APP_SECRET', // needed for the PHP SDK
        //'version'=>'v2.5', // Facebook API version to default to i.e. default_graph_version
        //'enable_beta_mode' => null, // optional Facebook\Facebook setting
        //'http_client_handler' => null, // optional Facebook\Facebook setting
        //'persistent_data_handler' => null, // optional Facebook\Facebook setting
        //'url_detection_handler' => null, // optional Facebook\Facebook setting
        //'pseudo_random_string_generator' => null, // optional Facebook\Facebook setting
        //'locale'=>'en_US', // override JS SDK locale setting (defaults to en_US)
        //'jsSdk'=>true, // include JavaScript SDK on all pages
        //'async'=>true, // load JavaScript SDK asynchronously
        //'jsCallback'=>false, // declare if you are going to be inserting any JS callbacks to the async JS SDK loader
        //'callbackScripts'=>'', // default JS SDK init callback JavaScript
        //'status'=>false, // JS SDK - check login status
        //'cookie'=>false, // JS SDK - enable cookies to allow the server to access the session
        //'xfbml'=>false,  // JS SDK - parse XFBML / html5 Social Plugins
        //'frictionlessRequests'=>false, // JS SDK - enable frictionless requests for request dialogs
        //'hideFlashCallback'=>null, // JS SDK - A function that is called whenever it is necessary to hide Adobe Flash objects on a page.
        //'html5'=>true,  // use html5 Social Plugins instead of older XFBML
        //'defaultScope'=>[], // default Facebook Login permissions to request with Login button
        //'redirectUrl'=>null, // default Facebook post-Login redirect URL
        //'userFbidAttribute'=>null, // if using FBAuthRequest, declare Facebook ID attribute on user model here
        //'accountLinkUrl'=>null, // if using FBAuthRequest, declare link to user account page here
        //'ogTags'=>[  // set default OG tags
            //'og:title'=>'MY_WEBSITE_NAME',
            //'og:description'=>'MY_WEBSITE_DESCRIPTION',
            //'og:image'=>'URL_TO_WEBSITE_LOGO',
        //],
        //'authenticationErrorCallback' => function(\Facebook\Exceptions\FacebookAuthenticationException $e) {
            // special logic for expired API accessTokens
            // prompt to re-authenticate?
            // log error?
            // throw $e?
            // return true?
        //},
        //'authorizationErrorCallback' => function(\Facebook\Exceptions\FacebookAuthorizationException $e) {
            // special logic for missing API permissions
            // prompt to authorize additional permissions?
            // log error?
            // throw $e?
            // return true?
        //},
        //'sdkErrorCallback' => function(\Facebook\Exceptions\FacebookSDKException $e) {
            // special logic for generic Facebook SDK errors
            // log error?
            // throw $e?
            // return true?
        //}
    ],
],

```

Then, to enable the JS SDK and Open Graph meta tag functionality in your base Controller, add this function to override the `afterRender()` callback:

```
protected function afterRender($view, &$output) {
    parent::afterRender($view,$output);
    //Yii::app()->facebook->addJsCallback($js); // use this if you are registering any additional $js code you want to run on init()
    Yii::app()->facebook->initJs($output); // this initializes the Facebook JS SDK on all pages
    Yii::app()->facebook->renderOGMetaTags(); // this renders the OG tags
    return true;
}

```

#### Installation without Composer

[](#installation-without-composer)

Included is an `autoload.php` file to assist in installing this extension without Composer. YMMV.

-
-

---

USAGE:
------

[](#usage)

### Open Graph meta tags

[](#open-graph-meta-tags)

Some Open Graph meta tags are set by default.

Set custom OG tags on a page (in view or action):

```

```

### Social Plugin helper widgets

[](#social-plugin-helper-widgets)

Render Facebook Social Plugins using helper Yii widgets:

```

```

You can, of course, just use the XFBML code for social plugins as well (if loading the JS SDK with XFBML = true):

```

```

### Run JS after Facebook JS SDK initializes

[](#run-js-after-facebook-js-sdk-initializes)

At any point you can add additional JavaScript code to run after the Facebook JS SDK initializes:

```

```

### Calling Facebook PHP SDK methods

[](#calling-facebook-php-sdk-methods)

To use the PHP SDK anywhere in your application, just call it like so (there pass-through the Facebook class):

```

```

### Graph API calls

[](#graph-api-calls)

Calling API methods directly on the `Yii::app()->facebook` component will automatically check for and add the proper accessToken for the logged in user. Call them like so:

```

```

### Facebook Exception Handlers

[](#facebook-exception-handlers)

If you call the SDK methods directly on the `Yii::app()->facebook` component then some default error handling logic will run. You can override this logic by specifying 3 different global Facebook error handlers:

- `authenticationErrorCallback` =&gt; `function(\Facebook\Exceptions\FacebookAuthenticationException $e)`
- `authorizationErrorCallback` =&gt; `function(\Facebook\Exceptions\FacebookAuthorizationException $e)`
- `sdkErrorCallback` =&gt; `function(\Facebook\Exceptions\FacebookSDKException $e)`

### Direct Graph API Calls

[](#direct-graph-api-calls)

If you want to make API calls *without* the default accessToken or *without* the global error handlers, call it via the `fb` property like this (`Yii::app()->facebook->fb`):

```

```

### Convenience Methods

[](#convenience-methods)

There are a couple of additional convenience methods added the component:

```

```

Also included are two helper classes: `FBAuthRequest` and `FBUserIdentity`

`FBAuthRequest` can be used to prompt a user to log in with Facebook if no active Facebook Session is detected. The message is displayed as a `notice` Flash message. You can optionally pass in Facebook permissions to prompt for.

```
\YiiFacebook\FBAuthRequest::fbLoginPrompt();
\YiiFacebook\FBAuthRequest::fbLoginPrompt(['manage_pages']);

```

`FBUserIdentity` is a base CBaseUserIdentity class that can be extended when adding Facebook authentication to your application.

---

BREAKING CHANGES:
-----------------

[](#breaking-changes)

- New version 1.x breaks everything from previous version and requires PHP 5.4
- 2.x version breaks most things, now using the PHP SDK v5 and Graph API v2.5

---

CHANGE LOG:
-----------

[](#change-log)

- 1.0.2-beta Updated to PHP SDK 4.0 and Open Graph API 2.2
- 2.0.0-beta Updated to PHP SDK 5.1 and Open Graph API 2.5

---

I plan on continuing to update and bugfix this extension as needed.

Please log bugs to the GitHub tracker.

Extension is posted on Yii website also:

The original version with support for Facebook SDK 3.x and Open Graph API 1.x was forked from ianare's faceplugs Yii extension:

Updated Feb 19th 2016 by Evan Johnson

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4142d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/68244dbb1f722c948000d77a73be13a556b84c453ed579b859031933cf302d6b?d=identicon)[thaddeusmt](/maintainers/thaddeusmt)

---

Top Contributors

[![thaddeusmt](https://avatars.githubusercontent.com/u/129787?v=4)](https://github.com/thaddeusmt "thaddeusmt (92 commits)")[![ianare](https://avatars.githubusercontent.com/u/697242?v=4)](https://github.com/ianare "ianare (3 commits)")[![brentjanderson](https://avatars.githubusercontent.com/u/45031?v=4)](https://github.com/brentjanderson "brentjanderson (1 commits)")[![kidsil](https://avatars.githubusercontent.com/u/154950?v=4)](https://github.com/kidsil "kidsil (1 commits)")[![nidgetgod](https://avatars.githubusercontent.com/u/4176953?v=4)](https://github.com/nidgetgod "nidgetgod (1 commits)")

---

Tags

facebookyiiopengraph

### Embed Badge

![Health badge](/badges/splashlab-yii-facebook-opengraph/health.svg)

```
[![Health](https://phpackages.com/badges/splashlab-yii-facebook-opengraph/health.svg)](https://phpackages.com/packages/splashlab-yii-facebook-opengraph)
```

###  Alternatives

[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[facebook/php-ads-sdk

PHP SDK for Facebook Business

9014.1M8](/packages/facebook-php-ads-sdk)[nickdnk/graph-sdk

Facebook SDK for PHP 8+

452.0M6](/packages/nickdnk-graph-sdk)[janu-software/facebook-php-sdk

Alternative toolkit for Facebook Graph API

71684.8k2](/packages/janu-software-facebook-php-sdk)[joelbutcher/facebook-graph-sdk

Facebook SDK for PHP

42728.5k1](/packages/joelbutcher-facebook-graph-sdk)[kerox/messenger

PHP Library to interact with Facebook Messenger Platform

58302.1k1](/packages/kerox-messenger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
