我有问题。$user_profile = $facebook->api('/me'); 有时它有效,有时则无效。
在 10 例中有 8 例它正在工作,突然我在 $user_profile 中有一个空字符串。魔法在哪里?
(我实现了最新的 php SDK)
// FB lib
require_once './libs/facebook.php';
error_reporting(0);
// connect
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'xxx',
'cookie' => true
));
$user = $facebook->getUser();
$fb_id = $facebook->getUser();
if ($user) {
try {
$_SESSION['user'] = $user_profile = $facebook->api('/me');
$_SESSION['fb_id'] = $fb_id;
} catch (FacebookApiException $e) {
error_log($e);
$user = NULL;
}
}
if ($user == NULL) {
$loginUrl = $facebook->getLoginUrl(
array(
'display' => 'popup',
'scope' => 'publish_stream, user_likes',
'redirect_url' => 'https://xxxx.cz/xxxx/canvas/index.php'
)
);
} else {
$_SESSION['fb_id'] = $fb_id;
header("Location: https://xxxx.cz/xxxx/xxxx.php");
}