duanchongzi9997 2014-08-11 02:36 采纳率: 0%
浏览 51
已采纳

instagram标签api功能

Can someone help me fix this code? result only appear 1 picture..

function get_instagram($q,$client_id) {
        $api = "https://api.instagram.com/v1/tags/".$q."/media/recent?client_id=".$client_id;
        $response = get_curl($api);
        $images = array();
        if($response){
            foreach(json_decode($response)->data as $item){     
                $src = $item->images->standard_resolution->url;
                $thumb = $item->images->thumbnail->url;
                $url = $item->link;

                $images[] = array(
                "src" => htmlspecialchars($src),
                "thumb" => htmlspecialchars($thumb),
                "url" => htmlspecialchars($url)
                );
                return "<a href='".$url."' target='_blank'><img src='".$thumb."' border='0'/></a>";
            }
        }
}

What I'm trying to achieve is make all result appear in a page

  • 写回答

2条回答 默认 最新

  • douze1332 2014-08-11 05:24
    关注

    In your code, you are getting only one image because, you are returning image inside loop so it dont executes all the records inside loop. Try below code

    function get_instagram($q,$client_id) {
        $api = "https://api.instagram.com/v1/tags/".$q."/media/recent?client_id=".$client_id;
        $response = get_curl($api);
        $images = array();
        $returnval = '';
        if($response){
            foreach(json_decode($response)->data as $item){     
                $src = $item->images->standard_resolution->url;
                $thumb = $item->images->thumbnail->url;
                $url = $item->link;
    
                $images[] = array(
                "src" => htmlspecialchars($src),
                "thumb" => htmlspecialchars($thumb),
                "url" => htmlspecialchars($url)
                );
                $returnval .= "<a href='".$url."' target='_blank'><img src='".$thumb."' border='0'/></a>";
            }
        }
        return $returnval;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)