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

元气小坏坏 提交于 2019-12-12 15:25:51

问题


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
    }

回答1:


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);


来源:https://stackoverflow.com/questions/24912112/how-can-i-get-imgur-com-album-images-using-ajax-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!