<?php
function get_photos($user_id=XXXX,$count=X,$width=XXX,$height=XXX,$token="XXXX"){
$url = 'https://api.instagram.com/v1/users/'.$user_id.'/media/recent/?access_token='.$token.'&count='.$count;
$cache = './BLAH/'.sha1($url).'.json';
if(file_exists($cache) && filemtime($cache) > time() - 1000){
$jsonData = json_decode(file_get_contents($cache), true);
} else {
$jsonData = json_decode(file_get_contents($url), true);
file_put_contents($cache,json_encode($jsonData));
}
$result = '<div id="instagram">'.PHP_EOL;
$i = 0;
foreach ($jsonData as $value) {
$title = (!empty($value->caption->text))?' '.$value->caption->text:'...';
BLAHBLAH
}
$result .= '</div>'.PHP_EOL;
return $result;
}
echo get_photos();
?>
foreach ($jsonData as $value)
出了什么问题?我在json_decode中使用“true”参数抓取一个数组..是不是那个foreach好吗?
这是json输入:http://pastebin.com/EBGG10hx