How to detect if a user is logged in?

Nov 19, 2008 at 2:00 PM
Edited Nov 19, 2008 at 2:03 PM

I have created a simple page that inherits from CanvasFBMLBasePage that does not require the user to login.  I set RequireLogin = False on PreInit because I want anyone to access my page even anonymously from outside facebook (like http://apps.facebook.com/wzhu_public_jsapi/).  The page works great and anyone from within facebook or outside of facebook can view the page - however I would like to add dynamic content users who have added my app, logged out users, etc. 

When RequireLogin = False I can't find a way to determine if a user is logged in - a few things I've tried:

  • API.uid always returns 0 - regardless if the user is a logged in user, logged out user, etc
  • API.users.getLoggedInUser() throws an "A session key is required for calling this method" error for both logged in users and logged out users

If I change RequireLogin = True then these methods return valid data...but of course then anonymous visitors can't access my page.  Does anyone know of a way to detect if a user is logged into facebook or if they have authorized my app from a page with RequireLogin = false?

Thanks,
Shane

Nov 21, 2008 at 9:21 PM
Hi Sue:

Were you able to figure this out?  I am trying to do the same thing.  It's weird that you get the exception even though a user is logged in.

Brian
Dec 7, 2008 at 8:42 PM
You can get it with Request.Form.Get("fb_sig_canvas_user"), facebook always passes that as pr. this page: http://wiki.developers.facebook.com/index.php/Automatic_Authentication
Sep 17, 2009 at 5:54 AM

@iskunkle: how to set requirelogin ?