2

I actually tried to find a solution but nothing and I hope I will find a solution here !

I use facebook connect in my website, everything works fine when I am logged on facebook, I am automatically logged into my site through facebook connect, and vice versa.

Now i tried to make it a facebook application but I have the following problem: I try to run inside the facebook iframe but unfortunately I'm not automatically logged in. sometimes it works, sometimes nothing happens , Sometimes I get this message: (Could not get the Facebook session. Your server may not Be Able Securely Facebook to connect to the user to retrieve information.)

some code im using :

include 'includes/facebook.php';

$facebook = new Facebook(array(
  'appId'  => $setting['facebook_appid'],
  'secret' => $setting['facebook_secret'],
  'cookie' => true, // enable optional cookie support
));

if ($facebook->getUser()) {
$facebook_session = 1;

try {
  $fb_user = $facebook->api('/me');
} catch (FacebookApiException $e) {
  error_log($e);
}

function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $application_secret) != $args['sig']) {
    return null;
  }
  return $args;
}

$cookie = get_facebook_cookie($setting['facebook_appid'], $setting['facebook_secret']);

$open = @file_get_contents('https://graph.facebook.com/me?access_token='.$cookie['access_token']);

if ($open != FALSE) {
    $fbdata = json_decode($open);
    $fb_user = array();

    foreach($fbdata as $key => $fbdata2) {
        $fb_user[$key] = $fbdata2;
    }
}

}
else {
    $facebook_session = 0;
}

ps: im using of course a Secure Canvas URL

Please help ! Thanks in advance

ShawnDaGeek
  • 4,145
  • 1
  • 22
  • 39

1 Answers1

0

My Facebook Connect login worked fine, but not inside the Facebook Canvas/iFrame it didn't work at all. I had to change my login method (now that facebook users have to be able to autologin in your application) and what basically worked for me was this: How to authorize Facebook app using redirect in canvas?

This is what I had before (I use CakePHP):

$params = array(
   'scope' => 'email'
);

$loginUrl = $facebook->getLoginUrl($params);
$this->redirect($loginUrl);

And I changed it to this which worked quite well:

$loginUrl = $facebook->getLoginUrl(
        array(
            'canvas' => 1,
            'fbconnect' => 0,
            'req_perms' => 'publish_stream'
        )
    );
echo '<script>top.location="'.$loginUrl.'";</script>';

I'm not sure if that really helps you as your app seems a bit more complicated than mine, but maybe you can solve your issue with this answer or the post I linked to.

Community
  • 1
  • 1
Christian Strang
  • 8,470
  • 5
  • 42
  • 53