Question on 'logged in" state with facebook-opengraph extension

Hi all,

I’m posting this on behalf of a colleague who ran out of time today, so bear with me. I’m not involved in his development right now, so I’ll do my best to ask this question without looking like a fool.

The question is essentially framed in the topic. He’s trying to implement Facebook registration and login for our Yii app and is essentially trying to find a “is the user logged in” method.

Can anyone who’s used this extension (http://www.yiiframework.com/extension/facebook-opengraph/) offer any insight? If I understand him correctly he gets all the user data when it’s invoked, but is unable to determine if the user is logged in or not. Does that make any sense? I will chat with him later to get more info, but based on what I’ve just said, if anyone has a suggestion or approach we’d sure appreciate it.

Thanks!

Michael

there is YiiAuth to try

http://www.yiiframework.com/forum/index.php/topic/32250-module-yiiauth/page__gopid__156490#entry156490

For that extension you linked to I also have a working demo

http://www.yiiframework.com/forum/index.php/topic/31548-bootstrapped-yii-blog-demo-with-facebook-and-persona-login/page__p__152016#entry152016

If only facebook is interesting I would recommend the last link, but if you want more like twitter,openid etc etc the first is by far a better options.

Colleague here to clarify the problem…

I have downloaded the Yii facebook-opengraph extension located here: http://www.yiiframework.com/extension/facebook-opengraph/

From what I can tell I have implemented the LoginButton correctly. After authenticating with Facebook (with the Facebook modal login), the login button updates through ajax and shows that I am logged in by displaying my Facebook image icon.

However, my problem is that I can not find a property that indicates that I am logged in on Facebook. This seems so trivial and it is probably something I am overlooking. When not logged in, I expected I could call


Yii::app()->facebook->getUser()

and the return value would be null or 0, but it is not… it is still displaying my last logged in Facebook user id. Somehow it seems this value is caching.

Is there any idea on how to fix this?

It looks like I’ve answered my own question minutes after posting. :) Hopefully this may help others, or perhaps someone has another helpful answer.

I noticed when the user was not logged into Facebook, calling


Yii::app()->facebook->getInfo()

would throw an exception. So I have used this in conjunction with destroying the session to fix my problem. See below.




try {

  	$userinfo = Yii::app()->facebook->getInfo();	

  } catch (Exception $e) {

  	Yii::app()->facebook->destroySession();

  }


echo Yii::app()->facebook->getUser(); // this is now equal to 0 if not logged into Facebook 




I still think it would be nice to have the following code implemented:




Yii::app()->facebook->isLoggedIn(); // boolean indicating whether user was logged into Facebook account



Thanks and hopefully someone may find this useful.

Why it returns a old userid is probably because u are still logged into facebook, i noticed some times I had to visit facebook.com and logout , some major problems overall.

I would still recommend hybridauth.