我用过这段代码:
(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);
但我得到了这个错误:
{ "data": { "error": "Malformed auth header","request": "\/3\/album\/NNbeO\/images","method": "GET" },"success": false,"status": 403 }
解决方法
我得到了解决方案.它现在工作正常.以下是我的工作代码.问题是,我没有添加带有授权标题的客户端ID文本:
(function($){ var albumID = 'NNbeO'; var albumAPI = "https://api.imgur.com/3/album/" + albumID + "/images"; $.ajax({ url: albumAPI,headers:{ 'Authorization':'Client-ID xxxxxxxxxxxxx' },success: function(data) { alert(data.data[0].link); },error: function() { console.log("ERRORZ"); } }); })(jQuery);