dr6673999 2013-09-10 12:59
浏览 26
已采纳

用于从Facebook中提取的图像库的PHP,仅获取前25个图像

Sorry if this seems like a dumb question, but I am realizing I have a LOT to learn about PHP. I was wondering what am I skipping, because as the title says, my image gallery using PHP takes images from a facebook site, but only pulls the first 25 pictures everytime, and all the pictures are public and uploaded by the same person. I am using a tutorial taken from this site: http://www.webdesignermag.co.uk/tutorials/facebook-image-gallery/

And the code used specifically is this:

<?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>';
?> 

And for the individual albums gallery is this:

<?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>'; 

    ?>
  • 写回答

1条回答 默认 最新

  • dongzhan5286 2013-09-10 13:07
    关注

    This has nothing to do with your PHP code; the URL you use to retrieve the JSON data only returns 25 <data> items (=pictures.)

    Chech the Facebook API documentation on how to either retrieve more than 25 pictures in a go, or how to specify an "offset" (so that you can retrieve pictures 26-50, for example.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条