I have a simple App that used to work in the old API. It's an iFrame app and I can't get the user session with the new API no matter what I try. Here is the code I have now:
<?php
error_reporting(E_ALL);
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxx',
'secret' => 'xxxx',
'cookie' => true,
));
$session = $facebook->getSession();
if ( !$session )
{
//echo "Failed. No session.<br />";
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'next'=>'http://www.facebook.com',
'cancel_url' => 'http://www.facebook.com'
));
//echo "<script type='text/javascript'>top.location.href = '$url';</script>";
echo "<a href='".$url."' target='_blank'>First time using this App? Click here to connect it to your Facebook.</a>";
}
else {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$updated = date("l, F j, Y", strtotime($me['updated_time']));
echo "Hello " . $me['name'] . "<br />";
echo "You last updated your profile on " . $updated;
} catch (FacebookApiException $e) {
echo "Error:" . print_r($e, true);
}
}
No matter what I try, $session is never returned (after clicking the link). I am using the correct appID/secret/facebook.php but it always falls into the !$session if path. What am I doing wrong?