PHP Instagram API-如何获得MIN_TAG_ID和MAX_TAG_ID


PHP Instagram API - How to get MIN_TAG_ID and MAX_TAG_ID

伙计们,我正在使用Instagram API获取带有特定标签的所有图像。

这是我的代码:

<?PHP
 function callInstagram($url)
    {
    $ch = curl_init();
    curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => 2
    ));
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
    }
    $tag = 'sweden';
    $client_id = "XXXX";
    $url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id='.$client_id;
    $inst_stream = callInstagram($url);
    $results = json_decode($inst_stream, true);
    //Now parse through the $results array to display your results... 
    foreach($results['data'] as $item){
        $image_link = $item['images']['thumbnail']['url'];
        $Profile_name = $item['user']['username'];
        echo '<div style="display:block;float:left;">'.$Profile_name.' <br> <img src="'.$image_link.'" /></div>';
    }

通过这个代码,我得到了20张带有标签sweden的图像。

我需要知道如何获得这个标签的min_tag_idmax_tag_id,这样我就可以进行类似分页的操作。

那么你能给我一些建议吗?我该如何获得最后一个帖子/图片的ID?

提前感谢!

从instagram文档:

PAGINATION
Sometimes you just can't get enough. For this reason, we've provided a convenient way to access more data in any request for sequential data. Simply call the url in the next_url parameter and we'll respond with the next set of data.
{
    ...
    "pagination": {
        "next_url": "https://api.instagram.com/v1/tags/puppy/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d&max_id=13872296",
        "next_max_id": "13872296"
    }
}
On views where pagination is present, we also support the "count" parameter. Simply set this to the number of items you'd like to receive. Note that the default values should be fine for most applications - but if you decide to increase this number there is a maximum value defined on each endpoint.

https://instagram.com/developer/endpoints/

Instagram的API返回带有"next_url"answers"next_max_id"节点的"分页"键。修改您的代码,以便如果是$result['pagination']['next_url'] != '',循环继续。

此处的文档:https://instagram.com/developer/endpoints/