0
如何確定訪問令牌是否已過期?最後一天,我能夠根據下面的代碼顯示信息,但是當我在第二天檢查它時,它不會重定向到Facebook。是否因訪問令牌?請幫助。謝謝如何處理在facebook api php sdk登錄時過期的訪問令牌?
// Get User ID
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;
$user = $facebook->getUser();
$token = $facebook->getAcessToken();
if ($user) {
try {
$user_profile = $facebook->api('/me');
$friends = $facebook->api('/me/friends');
}
catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl(array(
'next'=>'http://localhost/fb/php/examples/logout.php'
));
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email,read_stream'));
}
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<div>
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
</div>
<?php endif ?>
?></pre>
<?php echo $user; ?>
<pre>
<?php
print_r($user_profile);
?><pre>
<pre>
<?php
echo "=== LIST OF FRIENDS ===";
echo "<br/>";
$total_friends = count($friends['data']);
echo 'Total friends: '.$total_friends.'.<br />';
$start = 0;
echo '<br />';
while ($start < $total_friends) {
echo $friends['data'][$start]['name'];
?>
<?php
<img src="https://graph.facebook.com/picture"/> <?php echo $value["data"][$start] ['name']; ?>
<?php
echo '<br />';
$start++;}
?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
</body>
</html>
'getLoginUrl'將自動使用當前地址o'redirect_uri'值明確給出。 – CBroe
並且'getAcessToken' /'setAcessToken'東西也是不必要的 - 'getUser'會自動填充訪問令牌_if_它可以識別登錄用戶。 – CBroe