显示特定用户ID的某些标记的30 Instagram的图片 [英] Displaying 30 Instagram Images of certain tag of certain userID
问题描述
我有一个请求标记CrookedSpaces图像的Instagram的API调用,当这些图像返回我筛选确保从特定用户仅适用于图像(用他们的用户ID)的数据显示,code如下:
I have an Instagram API call that requests images tagged with CrookedSpaces, when those images return I am filtering the data making sure that only images from a certain user (using their userID), the code follows:
$(function() {
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "https://api.instagram.com/v1/tags/crookedspaces/media/recent/?count=100&access_token=TOKEN",
success: function(data) {
for (var i = 0; i < 31; i++) {
var igUID = data.data[i].user.id;
if(igUID === "USER ID") {
$(".instagram").append("\
<div class='instagram-feed'>\
<img class='instagram-image' src='" + data.data[i].images.standard_resolution.url +"' width='325px' alt='" + data.data[i].user.id + " " + igUID + "' onMouseOver=\"toggle_visibility('igImageHover" + i + "');\"/>\
<div class='igHover' id='igImageHover" + i + "' onMouseOut=\"toggle_visibility('igImageHover" + i + "');\">\
<div class='igHover2'>\
SMALL TEST!\
</div />\
</div>\
</div>\
");
} else {
console.log("Else portion of code ran " + elseCount + " time(s).");
++elseCount;
}
}
}
});
});
不过,我只能因为没有发表具体的用户ID 4图像显示27的图像。是否有某种方式来强制循环不增加?或减去1,从我不发送code进入一个无限循环?
However, I am only able to display 27 images because there are 4 images not posted by that specific userID. Is there some way to force the for loop to not increment? Or to subtract 1 from i without sending the code into an infinite loop?
下面是的jsfiddle - http://jsfiddle.net/UQcZP/
Here is the JSFiddle -- http://jsfiddle.net/UQcZP/
推荐答案
您可以使用while循环:
You could use a while loop:
var i = 0;
var used=0;
while (used<31)
{
if (i < data.data.length){
// .. Do your work here
// only increment used when you actually get a match
}
else
{
// Here we are past the end of the data and did not reach the 30 items,
// so just set the number of items to 31 to exit the loop.
used = 31;
}
i++;
}
这篇关于显示特定用户ID的某些标记的30 Instagram的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!