0
<?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

4

0 回答 0