我花了很多时间在本网站上的先前问题中找到我的解决方案,但却未能实现。
我的用户第一次进行身份验证时,该过程正常。但是当他们第二次返回时会出现异常:“OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。”
我认为SDK在较低级别处理令牌,因此我不需要处理它们?
$app_id = "XXXXXXXXXXXXXXX";
$app_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$site_url = "http://domain.com/";
try{
include_once "src/facebook.php";
}catch(Exception $e){
error_log($e);
}
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'read_stream, email, user_about_me, user_photos',
'redirect_uri' => $site_url,
));
}
try {
$albums = $facebook->api('/'.($_GET['fbuser'] ? $_GET['fbuser'] : 'me').'/albums');
} catch (FacebookApiException $e) {
print $e;
$user = null;
}
$access_token = $facebook->getAccessToken();
foreach($albums['data'] as $album):
[...]