从Facebook中提取的图片库的PHP只抓取前25张图片


PHP for an image gallery pulled from facebook, only grabs the first 25 images

对不起,如果这似乎是一个愚蠢的问题,但我意识到我有很多关于PHP的知识。我想知道我跳过了什么,因为正如标题所说,我使用 PHP 的图片库从 facebook 网站获取图像,但每次只提取前 25 张图片,并且所有图片都是公开的并由同一个人上传。我正在使用从本网站获取的教程:http://www.webdesignermag.co.uk/tutorials/facebook-image-gallery/

具体使用的代码是这样的:

<?php
    //Set the page name or ID
    $FBid = 'ArazaArtesanias';
    //Get the contents of a Facebook page
    $FBpage = file_get_contents('https://graph.facebook.com/'.$FBid.'/albums');
    //Interpret data with JSON
    $photoData = json_decode($FBpage);
    echo '<ul id="display-inline-block">';
    foreach ( $photoData->data as $data )
    {
        echo '<li><a href="getphotos.php?album_id='.$data->id.'">
                  <img class="shadow" src="https://graph.facebook.com/'.$data->id.'/picture/" width=70 border=0 />                  
                  </a>';
        echo '<br /><a href="getphotos.php?album_id='.$data->id.'">'.$data->name.'</a></li>';
    }
    echo '</ul>';
?> 

对于个人专辑库是这样的:

<?php
    //Get the contents of the album data page
    $rawAlbumData = file_get_contents('https://graph.facebook.com/'.$_GET['album_id'].'/photos');
    //Interpret data with JSON
    $photoData = json_decode($rawAlbumData);
    echo '<ul id="display-inline-block">';
    foreach ( $photoData->data as $data )
        {
            echo '<li><a href="'.$data->source.'" rel="lightbox" title="';
                if (property_exists($data, "comments")) {
                    foreach ( $data->comments->data as $Cdata )
                        {
                            echo htmlentities('<li class="imgcomments">
                                              <a href="http://www.facebook.com/people/@/'.$Cdata->from->id.'"    target="_blank">                                                                             <img src="https://graph.facebook.com/'.$Cdata->from->id.'/picture" 
                                              align=left border=0 />
                                              </a>&nbsp;
                                              <a href="http://www.facebook.com/people/@/'.$Cdata->from->id.'" target="_blank">
                                              <b>'.$Cdata->from->name.'</a>: </b>'.$Cdata->message.'<br />
                                              <div align="left" style="padding-bottom:10px;">
                                              <small>&nbsp;Posted '.timeSince(strtotime($Cdata->created_time)).' ago</small></div>                                                   </li>');
                        }
                }
                else {
                    echo 'There are no comments on this album';
                    }
            echo '"><img class="shadow" src="'.$data->picture.'" width=70 border=0 /></a></li>';
            }

    echo '</ul>';   
    //Get data about the photo album
    $rawCommentData = file_get_contents('https://graph.facebook.com/'.$_GET['album_id']);
    //Interpret comment data with JSON
    $commentData = json_decode($rawCommentData);
    echo '<div class="comments">';
    echo '<h2>Album Comments</h2>';
    if ( $commentData->comments->data ) {

        foreach ( $commentData->comments->data as $data )
        { 
            echo '&nbsp;<a href="http://www.facebook.com/people/@/'.$data->from->id.'" target="_blank"><b>'
                 .$data->from->name.'</a>: </b>'.$data->message.'<br/><div align="left" style="padding-bottom:10px;">
                 <small>&nbsp;Posted '.timeSince(strtotime($data->created_time)).' ago</small></div></li>';     
            }
    } 
        else {
            echo 'There are no comments on this album';
        }
    echo '</div>'; 
    ?>

这与你的PHP代码无关;你用来检索JSON数据的URL只返回25个<data>项目(=图片)。

查看Facebook API文档,了解如何一次检索超过25张图片,或如何指定"偏移量"(例如,您可以检索26-50张图片)。