Creating Facebook Connect

Hi, I won’t be doing an extension for Yii, You can just use this one with the documentation above to have the same result.

Hi There, I am using the new api, so in HFacebook.php I use:


but I am not getting a session loaded… can you help?

Hi there, I am having troubles with Facebook Connect -

it seams it must be a cookie issue - have you ever had the problem where fb connect window is not accepting your password even though your password is being entered correctly? Please let me know if you have any insights on this! Thanks!!!


Thank you for sharing your code, mech7. I’m using it as a guide for now and substituting the FB things using the library made by Vince (thank you too for your lib! Appreciated!).

I have a question. In the LoginController.php/LogoutController.php/UserIdentity.php files I see you’re instantiating an ‘User’ object model class. The thing is, shouldn’t we use ‘YumUser’ instead?

Am I missing something?

One thing that came to my mind was to create the User model class extending YumUser.

I’m going to test this extending-model-class thing anyway to see if it works.

EDIT: Question answered. Indeed, you’re extending YumUser. Sorry for the newbie’s Q. It happens. Often. :)

Vince, I made a little modification to your lib. In line 36, I modified the path this way:


This way I can put your library under Yii:app()->baseUrl . ‘/vendors/’ and then I can import it into Yii:

<?php	Yii::import('application.vendors.facebook.facebookLib'); ?>

Well, those were my today’s two cents. Thank you for your lib.

And now, the feature request. Is it possible you make facebookLib::includeScript() to receive an array in a ‘key’=>‘value’ fashion instead of the way you’re doing it right now?

hi everybody…!!

i just want some different situation here…which is probably name as disconnect facebook.

after a successful login with facebook. user is get registered in my app. and redirect to authenticate page.which is only accessible by logged in user.

Everything is working fine here.but now i want to disconnect user from facebook and make him alive on my that still he/she can access my application.

I am getting some problem here regarding cookies with yii.

my problem are listed here :-

(1) when a user click on log out button.still he is logged in my application.

(2) when a user click on a facebook disconnect button.then he will be logged out from facebook.but still showing connected on my app.

does anybody can help me here… even i am getting stuck with a authentication process of yii…

thanks in advance…

Dear all,

I bumped into this thread while researching for Yii support for Facebook authentication.

I ended up coding my own solution based on the OAuth 2.0 protocol and I would like to share.

This solution relies solely on Facebook authentication (no database) but it can serve as base for extensions.

It assumes the login route is ‘site/login’ provided through an https connection.

How to use it:


[*] Configure loginUrl and the Facebook properties in the main configuration file (you can set ‘scope’ to request more permissions).









		// 'scope'=>'email',








[*] Include the FacebookOAuthAction in your SiteController.

public function actions()


	return array(






[*] Include the FacebookLoginButton widget in your login view.

<?php $this->widget('FacebookLoginButton',array(

	'caption'=>'Login with Facebook',


)); ?>


And here follow the required components:


[*] The FacebookComponent class (requires the Facebook PHP SDK).


class FacebookComponent extends CApplicationComponent


	public $appId;

	public $appSecret;

	public $language='';

	public $scope='';

	public $optionsJS=array();

	public function init()


		if(!isset($this->optionsJS['appId'])) $this->optionsJS['appId']=$this->appId;


	public function initJS()








				var d = document.createElement("div"); = "fb-root";

				var b = document.getElementsByTagName("body")[0];

				b.insertBefore(d, b.firstChild);

				var e = document.createElement("script");

				e.type = "text/javascript";

				e.src = document.location.protocol+"//'.$this->locale.'/all.js";

				e.async = true;





	protected function getLocale()



		if(empty($language)) $language=Yii::app()->language;



		case 'de': return 'de_DE';

		case 'es': return 'es_ES';

		case 'fr': return 'fr_FR';

		case 'it': return 'it_IT';

		case 'ja': return 'ja_JP';

		case 'pt': return 'pt_PT';

		case 'pt_br': return 'pt_BR';

		case 'ru': return 'ru_RU';

		case 'sv': return 'sv_SE';

		default: return 'en_US';



	public function getRedirectUri()





		return Yii::app()->createAbsoluteUrl($route,$params,'https');


	public function getUserObject()




			$fb=new Facebook(array(




			return $fb->api('/me');


		catch(Exception $e)


			return false;




[*] The FacebookLoginButton widget.

class FacebookLoginButton extends CWidget


	public $caption='';

	public $htmlOptions=array();

	public function init()




		if(!isset($this->htmlOptions['class'])) $this->htmlOptions['class']='fb-login-button';

		if(!isset($this->htmlOptions['data-scope'])) $this->htmlOptions['data-scope']=$fb->scope;





				function flb_'.$this->id.'() {

					FB.getLoginStatus(function(response) {

						if (response.authResponse) {









	public function run()


		echo CHtml::tag('div',$this->htmlOptions,$this->caption);



[*] The FacebookOAuthAction class.

class FacebookOAuthAction extends CAction


	public function run()



		$identity=new FacebookUserIdentity();









[*] The FacebookUserIdentity class.

class FacebookUserIdentity extends CUserIdentity


	private $_id;

	public function getId()


		return $this->_id;


	public function authenticate()






			$this->errorMessage='Unable to authenticate user on Facebook.';

			return false;





		return true;




it’s not working…

I tried your solution but it not works… any ideas…?

How to download facebook client?

what is facebook client? is it facebook-php-sdk???

and where to place HFacebook.php file?