Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Instagram API(JSON+;PHP):显示从X开始的条目,而不是从0开始的条目_Php_Json_Api_Instagram - Fatal编程技术网

Instagram API(JSON+;PHP):显示从X开始的条目,而不是从0开始的条目

Instagram API(JSON+;PHP):显示从X开始的条目,而不是从0开始的条目,php,json,api,instagram,Php,Json,Api,Instagram,:) 这是我现在用来从Instagram中提取条目的代码: <?php setlocale(LC_TIME, 'it_IT'); function get_instagram($tag=bombacarta,$count=10,$width=612,$height=612){ $url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent/?access_

:) 这是我现在用来从Instagram中提取条目的代码:

        <?php
        setlocale(LC_TIME, 'it_IT');
        function get_instagram($tag=bombacarta,$count=10,$width=612,$height=612){
            $url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf&count='.$count;
            // Also Perhaps you should cache the results as the instagram API is slow
            $cache = './wp-content/themes/raymond-31/instagram_json/'.sha1($url).'.json';
            if(file_exists($cache) && filemtime($cache) > time() - 500){
                // If a cache file exists, and it is newer than 1 hour, use it
                $jsonData = json_decode(file_get_contents($cache));
            } else {
                $jsonData = json_decode((file_get_contents($url)));
                file_put_contents($cache,json_encode($jsonData));
            }
            $result = '<div style="border-top:1px solid #ddd">'.PHP_EOL;
            foreach ($jsonData->data as $key=>$value) {
                $location = (!empty($value->location->name))?'presso '.$value->location->name:null;
                $result .= "\t".'<em>'.htmlentities($value->caption->text, ENT_QUOTES, "UTF-8").'</em><br /><img src="'.$value->images->standard_resolution->url.'" alt="'.htmlentities($value->caption->text, ENT_QUOTES, "UTF-8").'" width="'.$width.'" height="'.$height.'" /><br /><div class="postinfo">Scattata da '.$value->caption->from->full_name.' il '.htmlentities(gmstrftime('%e %B %Y alle %R', $value->caption->created_time + 7200)).' '.htmlentities($location).'</div><br />'.PHP_EOL;
            }
            $result .= '</div>'.PHP_EOL;
            return $result;
        }
        echo get_instagram();
        ?>
试试这个:

  function get_instagram($tag=bombacarta,$count=10,$width=612,$height=612){
            $url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf&count='.$count;
            // Also Perhaps you should cache the results as the instagram API is slow
            $cache = './wp-content/themes/raymond-31/instagram_json/'.sha1($url).'.json';
            if(file_exists($cache) && filemtime($cache) > time() - 500){
                // If a cache file exists, and it is newer than 1 hour, use it
                $jsonData = json_decode(file_get_contents($cache));
            } else {
                $jsonData = json_decode((file_get_contents($url)));
                file_put_contents($cache,json_encode($jsonData));
            }
            $result = '<div style="border-top:1px solid #ddd">'.PHP_EOL;
            $ic=0;
            foreach ($jsonData->data as $key=>$value) {
                $location = (!empty($value->location->name))?'presso '.$value->location->name:null;
if($ic>=5){$res_c=thumbnail_resolution; $x_data="TESTT";}else{$res_c=standard_resolution;$x_data='Scattata da '.$value->caption->from->full_name.' il '.htmlentities(gmstrftime('%e %B %Y alle %R', $value->caption->created_time + 7200)).' '.htmlentities($location);}
$ic++;
                $result .= "\t".'<em>'.htmlentities($value->caption->text, ENT_QUOTES, "UTF-8").'</em><br /><img src="'.$value->images->$res_c->url.'" alt="'.htmlentities($value->caption->text, ENT_QUOTES, "UTF-8").'" width="'.$width.'" height="'.$height.'" /><br /><div class="postinfo">'.$x_data.'</div><br />'.PHP_EOL;
            }
            $result .= '</div>'.PHP_EOL;
            return $result;
        } 
函数get\u instagram($tag=bombacarta,$count=10,$width=612,$height=612){
$url='1https://api.instagram.com/v1/tags/“.$tag.”/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf&count=”.$count;
//此外,由于instagram API速度较慢,您或许应该缓存结果
$cache='./wp content/themes/raymond-31/instagram_json/'.sha1($url)。'.json';
如果(file_存在($cache)&&filemtime($cache)>time()-500){
//如果缓存文件存在,并且更新时间超过1小时,请使用它
$jsonData=json_解码(文件获取内容($cache));
}否则{
$jsonData=json_解码((文件获取内容($url));
文件内容($cache,json_encode($jsonData));
}
$result=''.PHP\u EOL;
$ic=0;
foreach($jsonData->data as$key=>value){
$location=(!empty($value->location->name))?'presso'。$value->location->name:null;
如果($ic>=5){$res_c=thumboil_resolution;$x_data=“TESTT”;}其他{$res_c=standard_resolution;$x_data='Scattata da'.$value->caption->from->full_name.'il'.htmlentities(gmstrftime('%e%B%Y alle%R',$value->caption->created_time+7200)).'.htmlenties($location)}
$ic++;
$result.=“\t”“.htmlentities($value->caption->text,ENT_引号,“UTF-8”)。
图像->$res_c->url.“alt=“”.htmlenties($value->caption->text,ENT_引号,“UTF-8”)。“width=“”。$width=“”。$height.”“/>
.$x_data.
; } $result.=''.PHP\u EOL; 返回$result; }
首先,感谢您的回复!!:D嗯..结果是:第六个条目仍然显示为其他条目..您在这里进行了一些缓存?这可能是问题所在。现在情况发生了变化,问题是第六个条目有一个emtpy..:)在第六张图片上,您只需要调整
$width
$height吗?还是您还需要将
$image->standard_resolution
更改为
$image->缩略图_resolution
?对于条目>5,我想将src更改为$image->缩略图_resolution.:)