简体   繁体   中英

Get ALL photos from a facebook album (PHP API)

I've got a problem with my source code. I've don't used since... 8/9 months and now, it doesn't work anymore.

I'm looking to list all my photos in my albums BUT, now it's listing me just 25 photos of each album and not more. I've got 100/200/250 photos per albums (party shootings) and I want to list them for my own website (to use Facebook bandwidth)

Here is my source code :

<?php 
    ob_start();
    session_start();
    include_once('facebook.php');
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Albums</title>
</head>
<body>
<?php

$params = array(
    'appId' => APP_ID,
    'secret' => APP_SECRET,
);
$facebook = new Facebook($params);
$user = $facebook->getUser();
$log = null;

if ($user) {
    $log = $facebook->getLogoutUrl();
} else {
    $log = $facebook->getLoginUrl(array('scope' => 'user_photos'));
}
echo '<a href="'.$log.'">' . (($user) ? 'logout' : 'login') . '</a>';
    if ($user) {
        $data = $facebook->api(
            '/me/albums',
            'GET',
            array(
                'fields' => 'id,name,privacy,photos.fields(id,name,images)',
                'limit' => '300'
            )
        );

        foreach ($data['data'] as $album) {
            echo '<div>';
                echo '<h3>' . $album['name'] . ' ' . $album['privacy'] . '</h3>';
                echo '<textarea style="width: 800px; height: 500px;">';
                    foreach ($album['photos']['data'] as $photo) {
                                echo $photo['images'][0]['source'].'';
                    }
                echo '</textarea>';

                echo '<textarea style="width: 800px; height: 500px;">';
                    foreach ($album['photos']['data'] as $photo) {
                               echo $photo['images'][7]['source'].'';
                    }
                echo '</textarea>';
            echo '</div>';
            //break;
        }
    }

    ?>
</body>
</html>
<?php ob_flush(); ?>

So if you're testing this code, you'll see that it listing to you all your albums but not all the pictures, it stops to 25.

Looks like you use limit in the wrong place. Try-

$data = $facebook->api(
           '/me/albums',
           'GET',
           array(
               'fields' => 'id,name,privacy,photos.fields(id,name,images).limit(300)',
               'limit' => '50'
           )
       );

In this case, FB will limit your albums to 50 and the photos within your albums to 300.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM