Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to load resource: net::ERR_CONNECTION_REFUSED for only selective images from instagram API

I am currently making a GET request to the instagram API to get a bunch of photos with a particular tag, and returning the JSON object I get in Rails back to the caller in JS, and setting the HTML with the img links and thumbnails etc. in the DOM.

What is weird is that, after restarting my server, I get this error:

Failed to load resource: net::ERR_CONNECTION_REFUSED 

for only some but not all of the photos which are returned by the 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();
    }
    });

Here is my Routes and finally my controller which makes the API call

  post '/application/get_instagram_photos', to: 'school_applications#get_instagram_photos'

Controller method

  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

end

UPDATE:

This is only happening on my development machine. After pushing to Heroku and viewing from other computers, the photos load fine except for still on my main work machine. It seems browser independent (tried Opera, Firefox, Safari, and Chrome) and adblock independent (Tried it on Chrome incognito as per a suggestion found on a similar SO post).

like image 856
Thalatta Avatar asked Nov 15 '14 01:11

Thalatta


1 Answers

I had a similar behaviour on my development machine where the error message would appear after editing my .htaccess for redirects. I could no longer access a specific website from any browser on any device in the same network (though I was able to access it from some shell commands). I strongly assume that my router had security concerns and blocked further access from browsers to the website. After about 24h I was able to access the website again.

Now it has been a while since this question was asked so I'm not going to ask you for setting up the same environment to test whether you also had a threshold of 24h and to further clarify the issue.

EDIT: Here is the link to the question where I was trying to fix the issue ERR_CONNECTION_REFUSED exclusively in browsers

like image 64
zyrup Avatar answered Nov 06 '22 18:11

zyrup