我目前正在GET
向 instagram API 发出请求以获取一堆带有特定标签的照片,并将我在 Rails 中获得的 JSON 对象返回给 JS 中的调用者,并使用 img 链接和缩略图等设置 HTML DOM。
奇怪的是,重新启动服务器后,我收到此错误:
Failed to load resource: net::ERR_CONNECTION_REFUSED
仅适用于 instagram API 返回的部分但不是全部照片。
var formdata = {tag: "myflsadventure"};
$.ajax({
url: "application/get_instagram_photos",
type: "POST",
datatype: 'json',
data: formdata,
success: function(response){
htmlz = "<div class='container'><div class='row'>";
count = 0;
rounded_style = " style='border:1px solid #; -webkit-border-radius: 20px; -moz-border-radius: 20px; border-radius: 20px;'"
$.each(response.data, function(i, item) {
if (count == 0 ){
htmlz += "<div class='col-md-6'><img src='"+item.images.standard_resolution.url+ "'" + rounded_style+"></div><div class='col-md-6'><div class='no-top'>";
count = count + 1;
}
else if (count == 9){
htmlz += "</div><div class='row'><div class='col-md-6'><div class='no-top'><div class='row'><div class='col-md-6'><img src='" + item.images.low_resolution.url+ "'" + rounded_style + "></div>";
count = count + 1;
}
else if (count == 13){
htmlz += "<div class='col-md-6'><img src='" + item.images.standard_resolution.url+ "'" + rounded_style + "></div></div></div>";
count = count + 1;
}
else if (count ==5){
htmlz += "</div><div class='row'><div class='col-md-3'><img src='" +item.images.low_resolution.url+ "'" +rounded_style+ "></div>";
count = count + 1;
}
else if ((count == 4) || (count == 12)){
htmlz += "<div class='col-md-6'><img src='"+item.images.low_resolution.url+ "'" + rounded_style +"></div></div></div></div></div>";
count = count + 1;
}
else if ((count == 6) || (count == 7) || (count == 8) ){
htmlz += "<div class='col-md-3'><img src='"+ item.images.low_resolution.url+ "'" + rounded_style + "></div>";
count = count + 1;
}
else if ((count == 3) || (count == 11)){
htmlz += "<div class='top'><div class='row'><div class='col-md-6'><img src='" + item.images.low_resolution.url + "'" + rounded_style + " ></div>";
count = count + 1;
}
else if ( count == 1){
htmlz += "<div class='row'><div class='col-md-6'><img src='" + item.images.low_resolution.url + "'" + rounded_style + " ></div>";
count = count + 1;
}
else{
htmlz += "<div class='col-md-6'><img src='"+ item.images.low_resolution.url+ "'"+ rounded_style + "></div></div>";
count = count + 1;
}
});
$("#myflsadventure").append(htmlz);
reapportion_les_fotos();
}
});
这是我的路线,最后是我的控制器,它进行 API 调用
post '/application/get_instagram_photos', to: 'school_applications#get_instagram_photos'
控制器方法
def get_instagram_photos
respond_to do |format|
uri = URI("https://api.instagram.com/v1/tags/#{params[:tag]}/media/recent?client_id=myIDc&count=14")
response = Net::HTTP.get(uri)
format.json {render :json => response}
end
结尾
更新:
这仅发生在我的开发机器上。推送到 Heroku 并从其他计算机查看后,照片加载正常,但仍在我的主要工作机器上。它似乎独立于浏览器(尝试过 Opera、Firefox、Safari 和 Chrome)并且独立于广告块(根据类似 SO 帖子中的建议在 Chrome 隐身模式下尝试过)。