可能重复:
为 foreach() 提供的参数无效
所以,我有这个功能:
<?php
function get_instagram($user_id=15203338,$count=6,$width=190,$height=190){
$url = 'https://api.instagram.com/v1/users/'.$user_id.'/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf&count='.$count;
// Let's create a cache
$cache = './wp-content/themes/multiformeingegno/instagram_json/'.sha1($url).'.json';
if(file_exists($cache) && filemtime($cache) > time() - 1000){
// If a cache file newer than 1000 seconds exist, use that
$jsonData = json_decode(file_get_contents($cache));
} else {
$jsonData = json_decode((file_get_contents($url)));
file_put_contents($cache,json_encode($jsonData));
}
$result = '<div id="instagram">'.PHP_EOL;
foreach ($jsonData->data as $key=>$value) {
$title = (!empty($value->caption->text))?' '.$value->caption->text:'...';
$location = (!empty($value->location->name))?' presso '.$value->location->name:null;
$result .= "\t".'<a class="fancybox" data-fancybox-group="gallery" href="'.$value->images->standard_resolution->url.'"><img src="'.$value->images->low_resolution->url.'" alt="'.$value->caption->text.'" width="'.$width.'" height="'.$height.'" /></a>
<div style="display: none;">'.htmlentities($title, ENT_QUOTES, "UTF-8").'<br><em style="font-size:11px">Scattata il '.htmlentities(strftime('%e %B %Y alle %R', $value->caption->created_time + 7200)).' '.htmlentities($location).' (<a target="_blank" style="color:darkgrey" rel="nofollow" href="http://maps.google.com/maps?q='.htmlentities($value->location->latitude).',+'.htmlentities($value->location->longitude).'">mappa</a>)</em></div>'.PHP_EOL;
}
$result .= '</div>'.PHP_EOL;
return $result;
}
echo get_instagram();
?>
我收到很多这样的错误:FastCGI 在标准错误中发送:“PHP 消息:PHP 警告:为 foreach() 提供的参数无效。问题所在是
foreach ($jsonData->data as $key=>$value) {
那有什么问题?
提前谢谢各位!:)