我有一個簡單的應用程序,用於在舊的API中工作。這是一個iFrame應用程序,無論我嘗試什麼,我都無法使用新API獲取用戶會話。這裏是我現在的代碼:Facebook PHP API /應用程序:iFrame
<?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);
}
}
無論我嘗試什麼,$ session永遠不會返回(點擊鏈接後)。我正在使用正確的appID/secret/facebook.php,但如果路徑始終落入!$會話中。我究竟做錯了什麼?