从Facebook提取图片库的PHP,仅获取前25张图片 [英] PHP for an image gallery pulled from facebook, only grabs the first 25 images

查看:42
本文介绍了从Facebook提取图片库的PHP,仅获取前25张图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,这似乎是一个愚蠢的问题,但是我意识到我有很多可以学习PHP的知识. 我想知道我跳过了什么,因为正如标题所述,我使用PHP的图像库是从一个Facebook网站上获取图像,但是每次只提取前25张图片,并且所有图片都是公开的,并且由同一个人上传. 我正在使用从此站点获取的教程: http://www.webdesignermag.co.uk/tutorials/facebook-image-画廊/

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

    ?>

推荐答案

这与您的PHP代码无关;用于检索JSON数据的URL仅返回25个<data>项(=图片).

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

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

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.)

这篇关于从Facebook提取图片库的PHP,仅获取前25张图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆