我需要将用户的相册显示在页面中。这段代码以前工作过,但现在它呈现一个空页面。我做错了什么?
$user = $facebook->getUser();
if ($user) {
try {
$albums = $facebook->api('/me/albums');
foreach($albums['data'] as $album)
{
$cover = "https://graph.facebook.com/{$albums['id']}/picture? type=album&access_token={$facebook->getAccessToken()}";
echo $album['name'];
echo "<img src='https://graph.facebook.com/cover_photo/picture?type=normal'/>";
}
}
catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
} else {
$loginUrl = $facebook-$loginUrl = $facebook->getLoginUrl(array('scope' => 'user_photos,friends_photos,user_photo_video_tags'));
echo "<script>top.location.href = '" . $loginUrl . "';</script>";
}
答案 0 :(得分:-1)
您的代码中存在一些小缺陷。
$album['data']
而不是$albums['data']
,您已经获得了封面照片的网址,因此您只需使用$cover
作为来源。以下是代码的审核部分:
foreach($albums['data'] as $album)
{
$cover = "https://graph.facebook.com/{$album['id']}/picture?type=album&access_token={$facebook->getAccessToken()}";
echo $album['name'];
echo "<img src='".$cover."'/>";
}