Search code examples
ajaximgur

How can I get imgur.com album images using ajax request


I used this code :

    (function($){
    var albumID = 'NNbeO';
    var albumAPI = "https://api.imgur.com/3/album/" + albumID + "/images";

    $.ajax({
        url: albumAPI,
        headers:{
            'Authorization':'xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        },
        type: 'GET',
        dataType: 'json',
        success: function(data) { 

            alert(data.data[0].link);

        },
        error: function() { console.log("ERRORZ"); }
    });
})(jQuery);

But I got this error :

 {
      "data": {
        "error": "Malformed auth header",
        "request": "\/3\/album\/NNbeO\/images",
        "method": "GET"
      },
      "success": false,
      "status": 403
    }

Solution

  • I got my solution. It works fine now. Below is my working code. It's problem was, I've not added Client-ID text with Authorization headers.:

    (function($){
    var albumID = 'NNbeO';
    var albumAPI = "https://api.imgur.com/3/album/" + albumID + "/images";
    
      $.ajax({
          url: albumAPI,
          headers:{
              'Authorization':'Client-ID xxxxxxxxxxxxx'
          },
          type: 'GET',
          dataType: 'json',
          success: function(data) { 
    
              alert(data.data[0].link);
    
          },
          error: function() { console.log("ERRORZ"); }
      });
    
    })(jQuery);