Instagram获取图片数量API


Instagram Fetch Amount of Images API

我的一个朋友写了这个脚本,显示了20张最新的instagram图片,我想知道,我该如何将它抓取的图片数量更改为6?

    <?PHP
$token = 'token';
$username = 'username';
$userInfo = json_decode(file_get_contents('https://api.instagram.com/v1/users/search?q='.$username.'&access_token='.$token));
if($userInfo->meta->code==200){
    $photoData = json_decode(file_get_contents('https://api.instagram.com/v1/users/'.$userInfo->data[0]->id.'/media/recent/?access_token='.$token));
    if($photoData->meta->code==200){ ?>
                <?PHP foreach($photoData->data as $img){
                    echo '<a href="'.$img->link.'?intent=like" target="_blank"><img src="'.$img->images->thumbnail->url.'"></a>';
                } ?>
    <?PHP } // If
} // If
    ?>

现在,这个脚本已经正常工作了,因为我已经花了一整天的时间,但我不知道如何更改它发送的数量。

另外,你们中有人知道如何设计这个吗?我已经为它做了CSS,但每当我尝试它时,它都无法正常工作。

而且,你知道如何使用API获得照片的描述吗?

提前感谢:-)

从端点请求数据时,需要使用Instagram的count= url参数。

例如:https://api.instagram.com/v1/users/search?count=6

或者在您的代码中:

<?PHP
$token = 'token';
$username = 'username';
$userInfo = json_decode(file_get_contents('https://api.instagram.com/v1/users/search?count=6&q='.$username.'&access_token='.$token));
if($userInfo->meta->code==200){
    $photoData = json_decode(file_get_contents('https://api.instagram.com/v1/users/'.$userInfo->data[0]->id.'/media/recent/?count=6&access_token='.$token));
    if($photoData->meta->code==200){ ?>
                <?PHP foreach($photoData->data as $img){
                    echo '<a href="'.$img->link.'?intent=like" target="_blank"><img src="'.$img->images->thumbnail->url.'"></a>';
                } ?>
    <?PHP } // If
} // If
?>

样式的伪示例。你需要弄清楚css样式,但应该不会太难。

<div class='myBorder'>
    <img url=$img->link />
    <div class='myCaption'>$img->caption->text</div>
</div>

获取描述

if (isset($img->caption)) {
    if (get_magic_quotes_gpc()) {
        $title = stripslashes($img->caption->text);
    } else {
        $title = $img->caption->text;
    }
}