可能是它不驗證它是第一次,你可以做一些這樣的事:
<?php
$facebook = new Facebook(array(
'appId' => xxx,
'secret' => xxx
));
$user_id = $facebook->getUser();
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$me = $facebook->api('/me','GET');
echo "Name: " . $me['name'];
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll redirect and
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl();
echo("<script>top.location.href = '" . $loginUrl . "';</script>");
}
} else {
// No user, redirect for the user to login
$login_url = $facebook->getLoginUrl();
echo("<script>top.location.href = '" . $loginUrl . "';</script>");
}
?>
編輯:
如果錯誤仍然存在,請嘗試使用此編輯,只是改變你的這條線:
$me = $facebook->api('/me','GET');
這樣:
$me= $facebook->api('/'.$user_id, 'GET');
希望這會解決您的問題。
如何嘗試捕捉? – AlphaMale 2013-02-22 14:19:54
我確實發現了這個錯誤,爲了簡潔起見我沒有表明。 – joe 2013-02-22 14:21:03
您是否檢查過getUser返回的內容? – CBroe 2013-02-22 14:27:13