1
votes

I am using javascript sdk to know if user is login and connected to our web-site' application by using FB.getLoginStatus() function. I want to know if php-sdk provides me details about the user logged into facebook. If user is logged in facebook and connected to our application, i have to make them to directly logged into our site. How can this be done using php sdk.

Thanks in advance.

4

4 Answers

1
votes

You can do the following:

$user_details=$fb->api_client->users_getInfo($fb_user, array('last_name','first_name','pic_square'));

And yes they do have a similar thing to the FB.getLoginStatus() :)

$params = array(
  'ok_session' => 'https://www.myapp.com/',
  'no_user' => 'https://www.myapp.com/no_user',
  'no_session' => 'https://www.myapp.com/no_session',
);

$next_url = $facebook->getLoginStatusUrl($params);

Found it here: https://developers.facebook.com/docs/reference/php/facebook-getLoginStatusUrl/

0
votes
0
votes

according to documentation ( https://github.com/facebook/facebook-php-sdk ), after doing:

require 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
));

// Get User ID
$user = $facebook->getUser();

To check if the user is still logged in on facebook (kind of FB.getLoginStatus) you need to:

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
0
votes

As noted by @DMCS this function should be used: http://developers.facebook.com/docs/reference/php/facebook-getLoginStatusUrl/

  1. You generate an url: $next_url = $facebook->getLoginStatusUrl();
  2. redirect the user to this url: header('Location: '.$next_url);
  3. the user will be returned by FB with session information (POST) about the login status
  4. the SDK will parse the return $_POST info
  5. use $facebook->getUser(); to get the userid (if logged in)

So far so good. The only problem is, this function (point 4) is broken since the transition to oAuth2.0 by Facebook, see also this bug report: http://developers.facebook.com/bugs/295348980494364

So please let FB know that you have the same issue by adding a reproduction.

Cheers!