Skip to content
Yii facebook opengraph including new facebbok migration handling
Latest commit 94a23a0 Dec 12, 2012 @hemendra619 format the code
Failed to load latest commit information.
php-sdk-3.2.2 files added Dec 12, 2012
plugins files added Dec 12, 2012
.gitignore Initial commit Dec 11, 2012
README.markdown files added Dec 12, 2012 format the code Dec 12, 2012
SBaseFacebook.php files added Dec 12, 2012
SFacebook.php files added Dec 12, 2012
facebook-channel.php files added Dec 12, 2012


This is mainly a wrapper for the Facebook PHP SDK class.

You can also use it to include the Facebook JS SDK on your pages, and easily set Open Graph meta tags.

Also included are helper widgets for all of the Facebook Social Plugins.

Facebook PHP SDK:

Facebook JS SDK:

Facebook Social Plugins:

Open Graph Protocol:

A lot of this comes from forking ianare's faceplugs Yii extension:


Copy the file "facebook-channel.php" to your project root.

Copy the rest of this extension in to your project's protected/extensions directory.

Include the extension in your Yii config:

    'class' => 'ext.yii-facebook-opengraph.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
    //'fileUpload'=>false, // needed to support API POST requests which send files
    //'trustForwarded'=>false, // trust HTTP_X_FORWARDED_* headers ?
    //'locale'=>'en_US', // override locale setting (defaults to en_US)
    //'jsSdk'=>true, // don't include JS SDK
    //'async'=>true, // load JS SDK asynchronously
    //'jsCallback'=>false, // declare if you are going to be inserting any JS callbacks to the async JS SDK loader
    //'status'=>true, // JS SDK - check login status
    //'cookie'=>true, // JS SDK - enable cookies to allow the server to access the session
    //'oauth'=>true,  // JS SDK - enable OAuth 2.0
    //'xfbml'=>true,  // JS SDK - parse XFBML / html5 Social Plugins
    //'frictionlessRequests'=>true, // JS SDK - enable frictionless requests for request dialogs
    //'html5'=>true,  // use html5 Social Plugins instead of XFBML
    //'ogTags'=>array(  // set default OG tags

Then, in your base Controller, add this function to override the afterRender callback:

protected function afterRender($view, &$output) {
  //Yii::app()->facebook->addJsCallback($js); // use this if you are registering any $js code you want to run asyc
  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;


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

<?php Yii::app()->facebook->ogTags['og:title'] = "My Page Title"; ?>

Render Facebook Social Plugins using helper Yii widgets:

<?php $this->widget('ext.yii-facebook-opengraph.plugins.LikeButton', array(
   //'href' => 'YOUR_URL', // if omitted Facebook will use the OG meta tag
   'send' => true
)); ?>

You can, of course, just use the code for this as well if loading the JS SDK on all pages using the initJs() call in afterRender():

<div class="fb-like" data-send="true" data-width="450" data-show-faces="true"></div>

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

<?php $userid = Yii::app()->facebook->getUser() ?>
<?php $loginUrl = Yii::app()->facebook->getLoginUrl() ?>
<?php $results = Yii::app()->facebook->api('/me') ?>

I also created a couple of little helper functions:

<?php $userinfo = Yii::app()->facebook->getInfo() // gets the Graph info of the current user ?>
<?php $imageUrl = Yii::app()->facebook->getProfilePicture($size) // gets the Facebook picture URL of the current user ?>
<?php $userinfo = Yii::app()->facebook->getInfoById($openGraphId) // gets the Graph info of a given OG entity ?>
<?php $imageUrl = Yii::app()->facebook->getProfilePictureById($openGraphId) // gets the Facebook picture URL of a given OG entity ?>


  • Before version 0.6 you didn't need to include the full OG meta tag (including the "og:" bit). Now you need to, to allow for new custom graph objects and actions. If you were setting OG meta tags like this Yii::app()->facebook->ogTags['title'] it now needs to be like this Yii::app()->facebook->ogTags['og:title'].


  • 0.6 Added support for custom OG meta tags, upgraded PHP SDK to 3.2, +some bugfixes
  • 0.6.1 Bugfix for the custom OG meta tags, which were overwriting the type, title and url tags

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

Please log bugs to the GitHub tracker here.

Extension is posted on Yii website also:

Updated Oct 7 2012 by Evan Johnson

Something went wrong with that request. Please try again.