Topic-icon Checking if user is logged in on FB

Active Subscriptions:

None
Hi,

I need to check if a user is logged in on Facebook.

I have the following code:
$fbClient = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $fbClient->getUserId(false);

Now, I allways get my FB userid, even if logged off from both Joomla and FB.

Am I misinterpreting the getUserId(false) call? Shouldn't it return null when I am logged off from Facebook?

My settings:
  • "Auto Login Facebook Users" = No
  • "Logout Of Joomla Only" = Yes (I've logged off from FB on FB directly)

Is this a session thing?

Thanks.
The topic has been locked.
Active Subscriptions:

None
AHAAA! Yep! Session thing...!

If I close the browser window (not just the tab) and open it again, it will work ok!

Hmmm... any suggestions on how I may bypass this?
The topic has been locked.
Support Specialist
14 years 8 months ago #13734 by alzander
Alexandre,
Depends on exactly what you're trying to do. First, the getUserId function was broken in 2 and deprecated (in 4.0) because the true/false parameter was confusing even to us. It will be removed entirely in a future version. You should use one of the following now instead, and their descriptions:
getFbUserId() - Gets the FB user id of user logged into Facebook. This is regardless of whether they are mapped to an existing Joomla Account
getMappedFbUserId() - Gets the FB user id of user logged into Facebook if they have a usermapping to a Joomla user

The first one will tell you, basically, if there's a cookie on your system from Facebook with a user's ID. This will be a user who's approved your site, but isn't necessarily logged into Joomla (or even has an account). Clearing your browser session will kill this cookie, which is what you're seeing. When you're user logs out of Facebook (either at fb.com or if you have the Logout of Joomla Only setting to 'no'), this cookie should be destroyed as well.

The 2nd will tell you if the above user is logged into Joomla.

Hope that explains, if not, let us know,
Alex
The topic has been locked.
Active Subscriptions:

None
Thanks for the "heads up" on getUserId () begin deprecated. I am now using getFbUserId().

By

alzander wrote: getFbUserId() - Gets the FB user id of user logged into Facebook

I understood that if the user is logged off, I would get a null value,
but what I notice is that getFbUserId() is returing a uid if a session cookie exists, not the actual state on FB (probably FB does not provide such info on its cookie).

I'll manage... somethings I seem to complicate the simple things ;)
The topic has been locked.
Support Specialist
14 years 8 months ago #13960 by alzander
Alexandre,
Sorry for not getting back to this sooner.

If the user's logged off of Facebook.com, yes, you should definitely get a null. If the user is logged into Facebook.com, it should be their ID.

The Facebook Javascript Library should actually be taking care of clearing the cookie for the user if they log off of FB.com and visit your site. However, it's possible this is related to the other autologin issue you mention.. where if a user logs of Facebook and visits your site, on that first visit, the cookie would be visible to your app, but the Javascript would clear it in when the page loads (PHP code already executed). The next page load, the cookie would be gone.

Hope that makes sense, but I can definitely see how that'd be a problem. If you think that's it, or if it rings any bells, let us know, and we'll look into this more.

Thanks,
Alex
The topic has been locked.