【问题标题】:PHP Instagram API - How to get MIN_TAG_ID and MAX_TAG_IDPHP Instagram API - 如何获取 MIN_TAG_ID 和 MAX_TAG_ID
【发布时间】:2015-03-25 19:08:57
【问题描述】:

伙计们,我正在使用 Instagrams 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 ?

提前致谢!

【问题讨论】:

    标签: php api instagram


    【解决方案1】:

    来自 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/

    【讨论】:

      【解决方案2】:

      Instagram 的 API 返回一个带有“next_url”和“next_max_id”节点的“分页”键。修改你的代码,如果$result['pagination']['next_url'] != '',循环继续。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-04-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-04
        • 1970-01-01
        相关资源
        最近更新 更多