我正在使用Instafeed.js(http://instafeedjs.com)从Instagram收集图像并在我的网站上显示。但我如何控制每张图片的大小,并控制它是低分辨率还是标准分辨率?

<script type="text/javascript">
    var userFeed = new Instafeed({
        get: 'user',
        userId: userID,
        accessToken: 'accessToken',
        resolution: 'standard_resolution',
        template: '<a href="{{image}}"><img src="{{image}}" /></a>'
        });
    userFeed.run();
</script>

过去我用过这段代码,但现在不起作用了:
<?php
// Supply a user id and an access token
$userid = "userID";
$accessToken = "acessToken";

// Gets our data
function fetchData($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $result = curl_exec($ch);
    curl_close($ch);
     return $result;
}

// Pulls and parses data.
$result = fetchData("https://api.instagram.com/v1/users/2254178/media/recent/?access_token=2254178.467ede5.4cf795f92f0a49b68724a782e706f6b5");
$result = json_decode($result);
?>

<?php $x = 1; ?>
if($x == 1) {
    echo'<a class="group left big" rel="group1" href="'.$post->images->standard_resolution->url.'"><img src="'.$post->images->standard_resolution->url.'"></a>';
    $x = 2;
}

else if($x == 2) {
    echo'<a class="group left small" rel="group1" href="'.$post->images->standard_resolution->url.'"><img src="'.$post->images->low_resolution->url.'"></a>';
    $x = 3;
}

最佳答案

我知道有点晚了,但是有一种简单且可扩展的方法可以用instafeed.js解决这个问题。
创建Instafeed实例时,应在模板中引用模型变量。例如:

<script type="text/javascript">
    var userFeed = new Instafeed({
        get: 'user',
        userId: userID,
        accessToken: 'accessToken',
        resolution: 'standard_resolution',
        template: '<a href="{{model.images.low_resolution.url}}"><img src="{{image}}" /></a>'
        });
    userFeed.run();
</script>

将为您提供链接到低分辨率图像的标准分辨率图像。通过允许访问整个JSON模型Instafeed,您可以对如何使用图像进行大量控制。
Stephen Schobert(instafeed作者)有一个很好的模型示例:https://github.com/stevenschobert/instafeed.js/issues/21

10-04 16:27