PHP Instagram API - 如何获取 MIN_TAG_ID 和 MAX_TAG_ID [英] PHP Instagram API - How to get MIN_TAG_ID and MAX_TAG_ID

查看:23
本文介绍了PHP Instagram API - 如何获取 MIN_TAG_ID 和 MAX_TAG_ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我正在处理 Instagram API 以获取带有特定标签的所有图像.

Guys I'm working around the Instagrams API to get all images with a specific tag.

这是我的代码:

<?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 标签的图像.

With this code I get 20 of the images with tag sweden.

我需要知道如何获取此标签的 min_tag_idmax_tag_id,以便我可以进行分页之类的操作.

I need to know how I can get the min_tag_id and max_tag_id for this tag so I can make a something like pagination.

那么你能给我任何建议,我怎样才能获得显示的最后一个帖子/图片的 ID?

So can you give me any advice how can I get the ID of the last post/image displayed ?

提前致谢!

推荐答案

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

Instagram's API returns a "pagination" key with the "next_url" and "next_max_id" nodes. Modify your code so that if $result['pagination']['next_url'] != '', the loop continues.

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

这篇关于PHP Instagram API - 如何获取 MIN_TAG_ID 和 MAX_TAG_ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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