Hi, Thanks for everyone's comments!
On Fri, Mar 13, 2009 at 10:25 AM, Jordi Boggiano <[email protected]> wrote: > I just wanted to ask, if you don't mind to share your code, that you > post it here (or mail it back to me), I could use a Facebook Connect > thingy but if I can avoid to dive into it I'd be happier :) The way I do it is perhaps a bit dodgy. On every request my server contacts Facebook to retrieve some user details, in order to ensure that the user has not logged out of Facebook elsewhere. This is obviously unnecessary and slows requests. It also sometimes fails and no data is retrieved from Facebook. However, I am paranoid about the user logging out of Facebook elsewhere, and expecting to be logged out of my site: so essentially I use the contact with Facebook to ensure the user is still logged in. Maybe I should limit this check to times where the user does 'something important'... Anyway: There is client-side Javascript code required, as explained on the Facebook Developers pages. Also, you need to create an application using the Facebook developer pages. This will give you an api key, and a secret key. So, server-side, using the Facebook php library: - In the startup method of your User class: $facebook = new Facebook($api_key, $secret); $fb_uid = $facebook->get_loggedin_user(); // Will be 0 if no user logged in - To retrieve details for the current user: $details = array('name','last_name','first_name','pic_small_with_logo','pic_with_logo'); $user_details = $facebook->api_client->users_getInfo($fb_uid, $details); $user_details = $user_details[0]; Then $user_details contains the requested details of the current logged-in user as an associative array. However, the above code can throw a FacebookRestClientException, which must be caught. Also, $user_details[0] might not be defined, and I do isset() check for it. I also then do an isset() check for each member of the $user_details array before reading them, as sometimes they aren't defined either. - If any of these details are not set, or if an exception is thrown I, due to paranoia, log out the user by: $facebook->expire_session(); (which, by the way, can also throw a FacebookRestClientException). I can give more details if you would like. Or, if someone has better ways of doing this, I would be very appreciative! Michal. _______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users
